Re: Automagical Invoice Generation

2009-01-26 Thread Almost George



On Jan 26, 10:52 am, Alfonso  wrote:
> I've got a very simple customer order model that saves the usual
> details into the system on a successful order placement.  I'm trying
> to think of a way I can generate an associative invoice at the same
> time an order is submitted?  Something within a custom 'def save'
> method?  How would I set something like that out?
>
> Thanks
>
> Al

Search docs for "Signals". It might be what you're looking for. I used
signals kind of like a message queue once -  There was a "listener"
that would create the related Broadcast every time an Event was saved/
updated, and later I could cycle through the new Broadcasts and act
upon them.

Something like that might be what you want?

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Events models - Concert/Single -vs- Tour/Festival

2009-01-26 Thread Almost George



Looking for some advice from anyone who's done something similar...
I'm working on a niche concert/event site, that essentially lists
upcoming events sorted by Date/City/Venue, etc.

Initially, my Event model (primarily) consisted of a Name and a Date
(start/end), Bands (m2m), and a FK to a Venue.

This model makes perfect sense, until thinking about things like
Festivals and Tours, which, to list,
have multiple dates, and multiple venues.

I'd like to be able to create a single instance of a "Festival", (not
duplicating the description, and other information),
but for each date it could have a unique Venue and Name ("Blah tour @
Fred's!").

My thinking on this took me in a circle, and I decided that probably
the best thing to do, especially
as far as scaling is concerned (I was not pre-optimizing, just
thinking through) is to simply have a "Duplicate Event"
button or some such, and add a FK type field to Event like "Belongs to
Tour/Festival" where tour/festival specific
information would exist. I'd predefine the bands and description info
in another model for Tour/Festival.

Issues there seem to be that it would require more with in the Views
possibly.

Either way seems like I'll be doing some nasty joins, etc, just to get
the list of bands for an Event.

Any ideas or similar implementations, projects, etc?

Sorry, I'm extremely verbose.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trouble with yesno to generate images

2009-01-26 Thread Almost George



On Jan 26, 3:39 pm, Margie  wrote:
> Hi,
>
> I am trying to generate a symbol for true and false in my table, but
> am having problems with the escaping of quotes and also with
> generating the < > tags.  If I use the code below:
>        {{ task.done|yesno:" \" />," }}
>
> it ends up generating this:
>
> 
>   
> 
>
> < ends up being <, > ends up being > and my quotes become
> "  Could someone give me an example of how to use yesno to
> generate an image?
>
> Margie

Sounds like your output is being "auto-escaped". Search the docs for
Auto Escaping, and how to control that in the template.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trouble with yesno to generate images

2009-01-26 Thread Almost George



On Jan 26, 3:58 pm, Almost George 
wrote:
> On Jan 26, 3:39 pm, Margie  wrote:
>
>
>
> > Hi,
>
> > I am trying to generate a symbol for true and false in my table, but
> > am having problems with the escaping of quotes and also with
> > generating the < > tags.  If I use the code below:
> >        {{ task.done|yesno:" > \" />," }}
>
> > it ends up generating this:
>
> > 
> >   
> > 
>
> > < ends up being <, > ends up being > and my quotes become
> > "  Could someone give me an example of how to use yesno to
> > generate an image?
>
> > Margie
>
> Sounds like your output is being "auto-escaped". Search the docs for
> Auto Escaping, and how to control that in the template.


Sorry for the extra post, but I thought I would provide a link:

http://docs.djangoproject.com/en/dev/ref/templates/builtins/#autoescape

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: trouble with yesno to generate images

2009-01-27 Thread Almost George



On Jan 26, 4:52 pm, Margie  wrote:
> Thanks very much, autoescape did the trick, here is the result for
> anyone interested:
>
>         {% autoescape off %}
>         {{ task.done|yesno:" \" alt=\"False\" />, \"False\" />" }}
>         {% endautoescape %}
>
> Margie

Margie,

 Thanks for being an awesome person and posting what worked for you!
More people should do that.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Adjusting these models for other functionality

2009-01-27 Thread Almost George

-- MODELS -- ( Other, unimportant fields/models have been removed )

class Band(models.Model):
name= models.CharField(max_length = 50, unique = True)

class Venue(models.Model):
name= models.CharField(max_length = 50)

class Event(models.Model):
name= models.CharField(max_length = 50, unique = True)
info= models.TextField(max_length = 200, blank = True)
date= models.DateTimeField()
bands   = models.ManyToManyField(Band)
venue   = models.ForeignKey(Venue)

If an Event is part of a Tour/Festival that has multiple dates (not
necessarily consecutive) I don't want to re-enter the bands and extra
info for each Event - where, essentially, I'll only have a different
Venue and Date assigned.

Currently, the Automatic Admin gives me the ability to quickly add/
change Bands and Venues for an Event, in one place. I'd like to keep
it that way if possible.

I've been thinking this into the ground on the best way to abstract
the Bands/Dates/Venues from the Event without causing rediculous
amounts of Joins to happen just to list the Events by date, and show
which Bands will be at each.

Also, with Dates/Venues abstracted, it (seems like it) makes it harder
to just get a list of Events by date,  and use Pagination, etc.

Any suggestions/ideas on how to alter the models to get a bit closer
to the functionality I desire?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Adjusting these models for other functionality

2009-01-28 Thread Almost George



On Jan 27, 9:56 pm, Malcolm Tredinnick 
wrote:
> On Tue, 2009-01-27 at 09:57 -0800,AlmostGeorgewrote:
> > -- MODELS -- ( Other, unimportant fields/models have been removed )
>
> >    class Band(models.Model):
> >            name    = models.CharField(max_length = 50, unique = True)
>
> >    class Venue(models.Model):
> >            name    = models.CharField(max_length = 50)
>
> >    class Event(models.Model):
> >            name    = models.CharField(max_length = 50, unique = True)
> >            info    = models.TextField(max_length = 200, blank = True)
> >            date    = models.DateTimeField()
> >            bands   = models.ManyToManyField(Band)
> >            venue   = models.ForeignKey(Venue)
>
> > If an Event is part of a Tour/Festival that has multiple dates (not
> > necessarily consecutive) I don't want to re-enter the bands and extra
> > info for each Event - where, essentially, I'll only have a different
> > Venue and Date assigned.
>
> > Currently, the Automatic Admin gives me the ability to quickly add/
> > change Bands and Venues for an Event, in one place. I'd like to keep
> > it that way if possible.
>
> > I've been thinking this into the ground on the best way to abstract
> > the Bands/Dates/Venues from the Event without causing rediculous
> > amounts of Joins to happen just to list the Events by date, and show
> > which Bands will be at each.
>
> You won't be able to create "ridiculous" amounts of joins. Databases are
> optimised to handle joins (certainly dozens at a time and often more),
> so stop trying to prematurely optimise. There's simply no other way to
> view what you're doing. Even with really huge and complicated schemas
> "normalise until it hurts; denormalise until it works" is the right
> order. You aren't approaching that order of complexity, so you can focus
> on step one for now.
>
> It sounds like an event should have a many-to-many relation to a
> date-range class that specifies the various dates. That will allow
> searches for events on a particular dates, dates for a particular event
> and so on. You should be able to organise things so that Festivals are
> simply Events.
>
> In fact, it seems to be that the whole structure here sort of rotates
> around Events. Without events, you have nothing, whether the event is a
> garage band gig or Woodstock. So I'd drive outwards from there. Events
> have multiple dates associated with them (as above -- I'd use a
> dateinterval style of class, but that's optional). They also have a
> many-to-many relation to bands, which is the band or bands that are part
> of the event. You might want to do that via a manual intermediate model
> (ManyToManyField(through=...) ) if the bands for an event also carry
> extra information (headliners, first support act, etc). And a Festival
> (name adjusted to choice) that is OneToOne with Event -- from Festival
> -> Event, since every Festival is an Event, but not vice-versa -- which
> provides extra information about the festival.
>
> There are possibly other structures, but that's one that comes to my
> mind after a little thought.
>
> Regards,
> Malcolm



Malcolm,

Thanks so much for your time and input. I thought I was "thinking
through" rather than pre-optimizing, but felt like I was leaving
something out (which was probably the indication of pre-opt')...
though I seemed to be drawing the same conclusions when "just doing
it" - so thanks for the prod in the correct direction. Tremendous
help. = )
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Can I control contents of SELECT in queryset?

2009-01-29 Thread Almost George



On Jan 29, 8:44 am, phoebebright  wrote:
> I want a distinct list of all the 'cat__names' that exist in
> Subcategory and have at least one entry in Business (Business is a
> subclass of model Directory which might be the problem)
>
> dir_query = Business.objects.all().select_related().distinct()
> ...
> subcats = dir_query.values('cat__name','cat').select_related().distinct
> ()
>
> But the SQL this generates has an additional field in the SELECT
> statement which means the DISTINCT does not have the effect I want and
> selects all entries.
>
> SELECT DISTINCT `town_subcategory`.`name`, `town_business`.`cat_id`,
> `town_directory`.`name`
> FROM `town_business`
> INNER JOIN `town_subcategory` ON (`town_business`.`cat_id` =
> `town_subcategory`.`id`)
> INNER JOIN `town_directory` ON (`town_business`.`directory_ptr_id` =
> `town_directory`.`id`)
> ORDER BY `town_directory`.`name` ASC
>
> Is there some way of forcing the fields in the select statement
> without having to write the whole SQL in raw format?  Or another way
> of writing the query?

Have you tried any of the methods listed in this article?
http://thisweekindjango.com/articles/2007/dec/21/retrieving-selective-fields-django/
( Retrieving Selective Fields with Django )
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: How to pass the variable which is defined in the views.py to the jQuery function

2009-01-30 Thread Almost George



On Jan 30, 6:09 am, min  wrote:
> Thanks a lot.
>
> Besides, what's the meaning for the 'escape_js' in [var x =
> "{{ variable|escape_js }}"] ?
>
> Regards
> Min
>
> On Jan 30, 4:33 pm, Malcolm Tredinnick 
> wrote:
>
> > On Thu, 2009-01-29 at 21:11 -0800, min wrote:
> > > Hi.
>
> > > First, the code in the forms.py:
>
> > > class TestForm(forms.Form):
> > >     name = forms.CharField( max_length=30 )
>
> > > Then, the variable is defined in the views.py:
>
> > > def Test_page(request):
> > >     form = TestForm()
> > >     show_results = False
> > >     variable = ''
> > >     if request.GET.has_key('name'):
> > >         show_results = True
> > >         query = request.GET['name'].strip()
> > >         variable  = 'custom value'
> > >     variables = RequestContext(request, {
> > >         'form': form,
> > >         'show_results': show_results,
> > >         'variable': variable
> > >          })
> > >     return render_to_response('Test.html', variables)
>
> > > I know the value of variable can be accessed by using {{variable}} in
> > > the Test.html. However, if I want use the jQuery in the Test.html and
> > > pass the value of this variable to the jQuery function, how to do
> > > that?
>
> > > I have tried: var x = $("variable").val(), and not succeed.
>
> > The context dictionary you pass to render_to_response is used by
> > render_to_response to produce a string. That string is what is sent back
> > to the browsers. The variables (parameters, whatever we want to call
> > them) are shoved into the template -- in a nice way; they're made very
> > comfortable -- and become static data in the final result. That is, they
> > are *not* variables from the browser's perspective. Template rendering
> > happens fully on the server side.
>
> > If you want to access this data via Javascript, you first have to make
> > it available as a Javascript variable in the template. For example, you
> > could write this in your template (inside a script block).
>
> >         var x = "{{ variable|escape_js }}";
>
> > The {{...}} bit is converted to a string by the (server-side) template
> > rendering. Then "x" is available to the browser-side Javascript. Clear
> > as mud?
>
> > Regards,
> > Malcolm- Hide quoted text -
>
> > - Show quoted text -



"escape_js" is a template filter that the value of "variable" is
passed through before being sent to the browser.

See http://docs.djangoproject.com/en/dev/ref/templates/builtins/#escapejs
and
http://docs.djangoproject.com/en/dev/ref/templates/builtins/#built-in-template-tags-and-filters
in general.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Question about Filtering on a Related model (I think) - with example code.

2009-02-09 Thread Almost George

On the following example models (actual models, removed of cruft that
doesn't seem to apply) I'd like to add a "get_upcoming_events" method
to Band like the one on Venue, but because of the relationship I'm not
sure how to use the API/filter. (An Event has the same bands, at
possibly different occurrences, whereas each Occurrence happens at a
particular Venue - if the models/structure needed justifying).

[ code highlighted @ dpaste: http://dpaste.com/118817/ ]

class Event(models.Model):
name= models.CharField(max_length=50, unique=True)
bands   = models.ManyToManyField(Band)

class EventOccurrence(models.Model):
name= models.CharField(max_length=50, blank=True)
venue   = models.ForeignKey(Venue)
event = models.ForeignKey(Event)
start = models.DateField()
end = models.DateField()

class Band(models.Model):
admin_approved = models.BooleanField(default=False)
name = models.CharField(max_length=50, unique=True)

def get_upcoming_events(self):
# How do I get Events, where the EventOccurrence.start is
filtered
# the same as this method on the Venue model?
pass

class Venue(models.Model):
name = models.CharField(max_length=50)

def get_upcoming_events(self):
return self.eventoccurrence_set.filter
(start__gte=datetime.today())


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Question about Filtering on a Related model (I think) - with example code.

2009-02-10 Thread Almost George

On Feb 10, 1:30 am, Daniel Roseman 
wrote:
> On Feb 10, 5:03 am, Almost George 
> wrote:
>
>
>
> > On the following example models (actual models, removed of cruft that
> > doesn't seem to apply) I'd like to add a "get_upcoming_events" method
> > to Band like the one on Venue, but because of the relationship I'm not
> > sure how to use the API/filter. (An Event has the same bands, at
> > possibly different occurrences, whereas each Occurrence happens at a
> > particular Venue - if the models/structure needed justifying).
>
> > [ code highlighted @ dpaste:http://dpaste.com/118817/]
>
> > class Event(models.Model):
> >     name    = models.CharField(max_length=50, unique=True)
> >     bands   = models.ManyToManyField(Band)
>
> > class EventOccurrence(models.Model):
> >     name    = models.CharField(max_length=50, blank=True)
> >     venue   = models.ForeignKey(Venue)
> >     event = models.ForeignKey(Event)
> >     start = models.DateField()
> >     end = models.DateField()
>
> > class Band(models.Model):
> >     admin_approved = models.BooleanField(default=False)
> >     name = models.CharField(max_length=50, unique=True)
>
> >     def get_upcoming_events(self):
> >         # How do I get Events, where the EventOccurrence.start is
> > filtered
> >         # the same as this method on the Venue model?
> >         pass
>
> > class Venue(models.Model):
> >     name = models.CharField(max_length=50)
>
> >     def get_upcoming_events(self):
> >         return self.eventoccurrence_set.filter
> > (start__gte=datetime.today())
>
> Looks like you could just use the same filter as in Venue, just adding
> 'event' before:
>     self.event.eventoccurence_set.filter(...)
> --
> DR.

That doesn't seem to work. Here's my manage.py shell session, which
appears as I expected it to: (hopefully email clients/google won't
screw up the quoting, otherwise see http://dpaste.com/118932/ )

>>> from xmx.models import Band
>>> b = Band.objects.get(name__startswith='r')
>>> b

>>> b.get_upcoming_events
>
>>> b.get_upcoming_events()
Traceback (most recent call last):
  File "", line 1, in 
  File "//x/django_projects/../xmx/models.py", line 39, in
get_upcoming_events
return self.event.eventoccurrence_set.filter
(start__gte=datetime.today())
AttributeError: 'Band' object has no attribute 'event'


- Any other suggestions?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Question about Filtering on a Related model (I think) - with example code.

2009-02-10 Thread Almost George



On Feb 10, 8:25 am, Almost George 
wrote:
> On Feb 10, 1:30 am, Daniel Roseman 
> wrote:
>
>
>
> > On Feb 10, 5:03 am, Almost George 
> > wrote:
>
> > > On the following example models (actual models, removed of cruft that
> > > doesn't seem to apply) I'd like to add a "get_upcoming_events" method
> > > to Band like the one on Venue, but because of the relationship I'm not
> > > sure how to use the API/filter. (An Event has the same bands, at
> > > possibly different occurrences, whereas each Occurrence happens at a
> > > particular Venue - if the models/structure needed justifying).
>
> > > [ code highlighted @ dpaste:http://dpaste.com/118817/]
>
> > > class Event(models.Model):
> > >     name    = models.CharField(max_length=50, unique=True)
> > >     bands   = models.ManyToManyField(Band)
>
> > > class EventOccurrence(models.Model):
> > >     name    = models.CharField(max_length=50, blank=True)
> > >     venue   = models.ForeignKey(Venue)
> > >     event = models.ForeignKey(Event)
> > >     start = models.DateField()
> > >     end = models.DateField()
>
> > > class Band(models.Model):
> > >     admin_approved = models.BooleanField(default=False)
> > >     name = models.CharField(max_length=50, unique=True)
>
> > >     def get_upcoming_events(self):
> > >         # How do I get Events, where the EventOccurrence.start is
> > > filtered
> > >         # the same as this method on the Venue model?
> > >         pass
>
> > > class Venue(models.Model):
> > >     name = models.CharField(max_length=50)
>
> > >     def get_upcoming_events(self):
> > >         return self.eventoccurrence_set.filter
> > > (start__gte=datetime.today())
>
> > Looks like you could just use the same filter as in Venue, just adding
> > 'event' before:
> >     self.event.eventoccurence_set.filter(...)
> > --
> > DR.
>
> That doesn't seem to work. Here's my manage.py shell session, which
> appears as I expected it to: (hopefully email clients/google won't
> screw up the quoting, otherwise seehttp://dpaste.com/118932/)
>
> >>> from xmx.models import Band
> >>> b = Band.objects.get(name__startswith='r')
> >>> b
> 
> >>> b.get_upcoming_events
>
> >>>> 
> b.get_upcoming_events()
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "//x/django_projects/../xmx/models.py", line 39, in
> get_upcoming_events
>     return self.event.eventoccurrence_set.filter
> (start__gte=datetime.today())
> AttributeError: 'Band' object has no attribute 'event'
>
> - Any other suggestions?

I'm going to wrap this up with the (a?) correct answer:
I was going about this backwards by going about it in a forward way. I
should have been thinking backwards, in other words.

I simply changed the Band model to have this method:

def get_upcoming_events(self):
"""
Get the list of upcoming events for this band.
"""
#return self.event_set.eventoccurrence_set.filter
(start__gte=datetime.today())
return EventOccurrence.objects.filter
(event__bands__id=self.id)

Starting with what I wanted, instead of "where I was".

If this is not the correct way (for intuitive or other reasons) please
let me know. Just wanted to make sure I put a "solution" to the
problem I posted.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: WYSIWYG Image upload challenge

2009-02-18 Thread Almost George



On Feb 18, 5:36 am, phoebebright  wrote:
> There is something different about the way django is handling to response to 
> php I think.


I use the YUI Rich Editor in admin, and have no problems. I know
debugging isn't as easy in IE as others, but do your best to find out
the exact response (mostly, response headers) that's being sent to the
browser. Also, could you clarify the above "response to PHP"
statement? Perhaps explaining the technical details of what's going on
would be of some help?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



From example models, how to highlight relation in Template

2009-04-25 Thread Almost George

I have (essentially) the following models:

class AttendanceRelation(models.Model):
event = models.ForeignKey('swingtime.Occurrence')
attendee = models.ForeignKey('AttendeePerson')

class AttendeePerson(models.Model):
first_name= models.CharField(blank=False, max_length=100)
middle_name   = models.CharField(blank=True, max_length=100)

---

I'm sending either AttendeePerson.objects.all() or a filtered version
of it to the template to list people. I'd like to know how best use
results from AttendanceRelation objects to highlight all of the users
that have one.

Assume I'm just listing AttendencePerson.objects.all(), and only a
subset of those people exist in the QS like
AttendenceRelation.objects.filter(event__id="1").

How do I somehow highlight or mark those people in a Template? That I
understand, I can't just do an "If Person In ..." in the Templates.

Am I wrong? Did I screw up my models from the outset? Any pointers?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Using 'django-filter' on a field with choices

2009-09-21 Thread Almost George

I'm using the very cool django-filter (via: 
http://github.com/alex/django-filter)
and either can't seem to wrap my head around the docs, or maybe just
need a little boost.

When I show the filter form on an object list page, for a FK field I
get the dropdown that includes a "-" which kind of results in an
"any" type filter. But I have some choices set to a field on that
model, and I'd like to get the same "any" type option, but I don't.

Here's a relevant example portion from models.py:


---

TICKET_STATUS_CHOICES = (
('new', 'New'),
('accepted', 'Accepted'),
('assigned', 'Assigned'),
('reopened', 'Reopened'),
('closed', 'Closed'),
)

class Ticket(models.Model):
assigned_to = models.ForeignKey(User, null=True, blank=True)
status = models.CharField(max_length=20,
choices=TICKET_STATUS_CHOICES, default='new')

import django_filters

class TicketFilter(django_filters.FilterSet):
class Meta:
model = Ticket
fields = ['assigned_to', 'status']

--

When I display the filter form, 'assigned_to' gets an 'any' option, as
well as listing the available users. The 'status' field, however, is
limited to only the options listed in the actual '_CHOICES'.

How do I add an 'any' option to the fields based on _CHOICES?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Using 'django-filter' on a field with choices

2009-09-21 Thread Almost George



On Sep 21, 8:54 am, Almost George 
wrote:
> I'm using the very cool django-filter 
> (via:http://github.com/alex/django-filter)
> and either can't seem to wrap my head around the docs, or maybe just
> need a little boost.
>
> When I show the filter form on an object list page, for a FK field I
> get the dropdown that includes a "-" which kind of results in an
> "any" type filter. But I have some choices set to a field on that
> model, and I'd like to get the same "any" type option, but I don't.
>
> Here's a relevant example portion from models.py:
>
> ---
>
> TICKET_STATUS_CHOICES = (
>     ('new', 'New'),
>     ('accepted', 'Accepted'),
>     ('assigned', 'Assigned'),
>     ('reopened', 'Reopened'),
>     ('closed', 'Closed'),
> )
>
> class Ticket(models.Model):
>     assigned_to = models.ForeignKey(User, null=True, blank=True)
>     status = models.CharField(max_length=20,
> choices=TICKET_STATUS_CHOICES, default='new')
>
> import django_filters
>
> class TicketFilter(django_filters.FilterSet):
>     class Meta:
>         model = Ticket
>         fields = ['assigned_to', 'status']
>
> --
>
> When I display the filter form, 'assigned_to' gets an 'any' option, as
> well as listing the available users. The 'status' field, however, is
> limited to only the options listed in the actual '_CHOICES'.
>
> How do I add an 'any' option to the fields based on _CHOICES?


I figured out a decent-enough solution to this. I'm sure others could
point out a more Pythonic or DRY way. See:
http://stackoverflow.com/questions/1455415/using-django-filter-with-choices-field-need-any-option
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Merge models?

2009-09-22 Thread Almost George

Wondering if there is already work being/been done on making it easy
to merge models. It may be much easier than I think, but I thought I
would ask anyway.

Here's my specific scenario:

On a site where users contribute a good deal of content, someone might
come across a piece of content that could be considered a duplicate -
an item, an article about a person, (a "question" in the case of stuff
like StackOverflow).

I'd like to be able to allow certain users to very easily be able to
flag a duplicate, find the "other" model, and easily merge/fix the
differences. One example is a Wiki with a page about "John Smith", and
another about "Jhon Smith". In one case, the user simply spelled the
name wrong. But perhaps there's some valuable meta-data, like "Links
to John Smith Websites", and the first article has a few that aren't
listed on the second.

I'd like to make it fairly simple for a user to say "Hey, *this*
article/item/model is correct, *this other one* is a duplicate, and
keep the unique links from #2" make some final edits, and be done. The
2nd model would (probably) be (soft) deleted.

I'm definitely not wanting to reinvent any wheels - so I'm looking for
other projects that include some functionality like this, to at least
look at as a starting point for how to do this correctly.

Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Complicated Form "Workflow" - Need ideas/direction

2009-12-14 Thread Almost George
I have a working site, and the admin works fine for what I'm doing. I
have 3 primary models: an Event, an Attendee, and a Venue.

In the admin, an Event created *must* have at least one Attendee, and
must, obviously, have a Venue (location).

I'd like to open up the site for user submissions (users can create
new Events, choosing/creating Attendees and Venues), but I can't
figure out how the workflow / form would work. Mostly because of the
requirements, as such:

An Attendee, being added to an Event, must already exist in the
system. If the given Attendee doesn't exist, the user should be
prompted to create it/them (validly) before continuing further.

Likewise when selecting the Event Venue - if it doesn't exist, it must
be created.

Of particular note, Venues have some required meta-information that
must be filled out before it can be considered valid.

That's quite a bit of "add and/or create+validate", and I'm not sure
how to implement that. I'm assuming I'll be using the Form Wizards,
but at this point I'm just not sure where to start.

Can anyone offer a bit of direction or advice on how to implement a
workflow like that?

Thanks much for any assistance!

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Complicated Form "Workflow" - Need ideas/direction

2009-12-14 Thread Almost George


On Dec 14, 2:23 pm, Shawn Milochik  wrote:
> What you're trying to do is simple enough to write out in flowchart form on a 
> sheet of paper. You should do that, then write some code, then ask for help 
> with specifics when you get stuck, or are trying to decide between different 
> approaches. What your e-mail sounds like, whether you intend it or not, is 
> asking other people to do your work for you. If you have any specific 
> questions (more specific than 'how to implement a workflow like that'), then 
> by all means ask them.
>
> Also, this sounds like homework.
>
> Shawn


Terribly sorry that this sounds like homework, or lazy. Wasn't
intended to. I'm always careful to specify "a bit of advice or
direction", in the hopes that the person reading it will realize that,
though the problem to them seems trivial, for one reason or another I
know what I'm doing and just need a bit of a boost in the right
direction.

As I've been looking at it, it seemed a bit complicated - probably
because I'm approaching this with the Old mindset of the web, where I
would have to maintain my own state, etc., and didn't have the
framework here to help me.

Now that I've done a bit more reading, I realize that the Form Wizard
stuff will probably be exactly what I need, I'll just have to create
the appropriate forms for each model, and decide what order to place
things.

I think part of my over-complicating the issue for myself was that I'm
imagining too many user interface details during the thought-process,
instead of focusing on the problem solely at the back-end.

Here's a specific problem that I don't know how to approach:

On the first form, the user chooses the Date and meta-details for an
Event (name/description).
On the second form, the user should be prompted to select an existing
Venue where the Event will take place. At this point, I would like the
user to be able to create a new Venue if necessary. Obviously, the New
Venue form will validate the required meta-information for a Venue. My
problem: I hate pop-ups. And, as far as I can tell, the default way
(as-in, the way Django Admin does it) to add a model on the fly is via
a pop-up. Aside from that, I guess I could dynamically add 'New Venue'
forms to the current form page, but in that case, I have no idea how
they should be validated/handled when attempting to move to the next
page.

Can the Form Wizard handle this type of branching-and-returning to the
last place in the form, or should I just attempt to tackle this kind
of thing myself?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Complicated Form "Workflow" - Need ideas/direction

2009-12-14 Thread Almost George


On Dec 14, 3:04 pm, Shawn Milochik  wrote:
> Okay, here are a few ideas:
>
> 1. If you hate pop-ups, but aren't opposed to a little AJAX, then you could 
> do it that way.
>
> 2. You could do it with a multi-screen, 'wizard-like' set of templates.
>
> 3. You can keep state using session variables.
>
> 4. If you don't want to worry about keeping session variables, you can have a 
> menu somewhere listing the possible activities (add attendee, add venue, 
> etc.) If someone tries to do one, and finds that they don't have a required 
> item, they'll have to click a different menu item, do the creation, then 
> click the original choice and select the newly-added item.
>
> By the way, it doesn't sound right that you need an attendee for an event. 
> Events, in my imagination, always have zero or more attendees. Zero upon 
> creation, and possibly more as attendees register to attend.
>
> Of those items mentioned above, I prefer AJAX (using jQuery). However, 
> depending on the audience for your application, you may need to ensure that 
> it works on browsers that have JavaScript enabled, so you may choose another 
> route in addition to (or instead of) AJAX.
>
> I hope this was helpful. If not, let me know what I'm not understanding about 
> your questions.
>
> Shawn


Shawn,

Thanks. I appreciate your time and assistance.
You're right about Event/Attendee relationship, although there's a
good reason for it when looking at my actual models and their purpose.
And the fact that I lied, and Attendees are actually something else.
One day I'll learn to give better examples of actual circumstances -
just thought the analogy was good enough to get started, without other
complicated context-sensitive information.

The reason I'm opposed to pop-ups and multiple-separate-steps (your
#4) is that I'm trying to streamline the process for the user, while
taking a "progressive enhancement"/accessibility approach. I'd like to
get the flow working "old-school", and then build in AJAX on top of
that.

In this case, a person creating an new Event would know all of the
necessary details (Venue location, etc), but we may not have the Venue
listed already, with the necessary meta-information.

You've been a great help, and I suppose I'll push on until I hit
another, more specific wall.

Thanks again.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Notification of Model Changes

2010-08-24 Thread Almost George
This is probably a very old question, but I wasn't able to find an
obvious answer - sorry if I overlooked anything.

I have a model with a "status" field (using Choices) that defaults to
"pending" and has other options like "closed", "active", etc.

I would like to implement email notifications of changes to this
model, particularly concerning this field.

I figure that a custom signal might work, but I'm not sure where to
put it.

In pre_save (the only place I know that I have access to the "old"
value), I don't know yet that the object actually finished saving
correctly. In post_save, I don't think I have the old value to compare
to the new.

The notification should be able to contain something along the lines
of "user x changed blah status from Y to Z".

Where should I be looking to utilize old-vs-new comparison, and to
generate a signal or some such, so as to handle this in an appropriate
fashion?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Notification of Model Changes

2010-08-24 Thread Almost George

On Aug 24, 2:15 pm, Shawn Milochik  wrote:
> If you override __init__() and store the value of that field in a
> temporary value, such as self.old_status, then the instance will have
> both self.status and self.old_status for comparison later.
>
> I hope this fits your use-case.
>
> Shawn

Sounds great, thanks!

When overriding __init__, what does that function definition need to
look like to make sure everything else works as usual?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.