List Info

Thread: inheriting from models.Model




inheriting from models.Model
user name
2006-06-29 09:08:53
Hi,
some time ago i did something similar and wondered to get
some problems
using
the query manager. So when i used

class Comment(models.Model):
class VideoComment(Comment):

and then asked
VideoComment.objects.get(id='xyz')
the Manager tried to to look up the Comment Table

My solution was to explicitely set the default manager
inside the
derived class like:

class VideoComment(Comment):
   objects = models.Manager()

besides that there seems to be some discussion on
inheritance for not
yet
beeing implemented in the development version


hope this helps

knobi


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

inheriting from models.Model
user name
2006-06-29 09:27:23
for this problem i used the Generic foreign
key/relationships. an
example in the documentation:
http://www.djangoproject.com/documentation/m
odels/generic_relations/

although i didn't find anything about it in the Model API.

there is another thing i'd like to do with the above
comments example:
what if for video and user comments there is an extra field
char field.
and this char field need different choices (i.e.
choices=VIDEO_COMMENT_CHOICES) for video and user comments.
is there a
way to fit this in the generic relation way? the way i'd
think it would
work is:

class Comment:
    CHOICES = ()
    comment = models.TextField()
    choice = models.charField(choices=CHOICES)

class VideoComment(models.Model, Comment):
    CHOICES = (('a', 'Apple'), ('p', 'Pear'))
    video = models.ForeignKey(Video)

class UserComment(models.Model, Comment):
    CHOICES = (('a', 'Admin'), ('p', 'Public User'))
    user = models.ForeignKey(User)

the CHOICES in VideoComment would then be used instead of
the blank on
in Comment. (i'm new to python so don't know if this is
actually
viable)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )