Hi,
I have the following:
class Event(models.Model):
date = models.DateTimeField()
description = models.TextField()
def __str__(self):
return self.date
class Admin:pass
class CheckList(models.Model):
name = models.CharField(max_length=32)
event = models.OneToOneField(Event)
attended = models.BooleanField()
was_drunk = models.BooleanField()
silly_walk = models.BooleanField()
naughty = models.BooleanField()
been_seen = models.BooleanField()
def __str__(self):
return self.name
When I populate and save an object instance of class Event does it create a
corresponding instance of bar based on the one to one relationship
automatically?
I have date based events (one per day) that need a corresponding table of
boolean values, like a check list, to be filled out later. The event is
scheduled and then the check list is processed on that day, so I'm trying
to properly do the following:
1. If possible, when a Event object is created; create the corresponding
CheckList object automatically. Ready to be filled out from a view.
2. A CheckList's most proper "name"; i.e., what I'd like to return via the
admin app in list view when __str___(CheckList_obj) is called would be the
corresponding date of the related event, not sure how to do this within the
Django model context, pretty sure how I'd do things from a Python point of
view.
I've thought about having the CheckList object instanced by the __init__
method for Event, passing in the date from the Event object to be used in
the __str__ method.
But I guess I should poke around in the classes Django is providing and see
how they are structured and see what I can take advantage of better there.
If anyone has a quick insight into clean & correct ways to do this with
Django, or ways I could better model and refactor this. Perhaps it is what I
want to do that is wrong even before considering how to do it.
I just don't want to break the nice SQL generation / data modeling going on
by inadvertently trying to make it do something without understanding more
fundamentally how it is working at low-level and I haven't got there yet.
Thanks much!
--
John Morris
[EMAIL PROTECTED]
"Do nothing which is of no use." -- Miyamoto Musashi
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---