I have some models setup that allows users to have an inventory of
items: books and movies. These are setup as inherited models.

What I would like to do is allow a user to select a current book and a
current movie, but only from "valid" options in that user's inventory.
What I mean by valid is that a user should not be able to select a
book as their current movie, or a movie as their current book.

Here is what I have so far. This works, except that it does not limit
the user to what is in their inventory, nor does it validate that the
current_book is actually a book.

Any thoughts or ideas of how to achieve this?

class Profile(models.Model):
    user = models.ForeignKey("auth.User", verbose_name="User",
unique=True)

    # These are the two lines that are not correct
    current_book = models.ForeignKey("Inventory", blank=True,
null=True, verbose_name="Current Book",
related_name="profile_current_books")
    current_movie = models.ForeignKey("Inventory", blank=True,
null=True, verbose_name="Current Movie",
related_name="profile_current_movies")

class Item(models.Model):
    name = models.CharField("Name", max_length=60)
    description = models.TextField("Description", blank=True,
null=True)

class Book(Item):
    pages = models.PositiveIntegerField("Pages")

class Movie(Item):
    minutes = models.PositiveIntegerField("Minutes")

class Inventory(models.Model):
    item = models.ForeignKey("Item", verbose_name="Item")
    profile = models.ForeignKey("Profile", verbose_name="Profile")
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to