You can use model inheritance

class SomeCommonNameHere(models.Model):
    title = models.CharField(max_length=100)
    body = models.TextField()

class Casts(SomeCommonNameHere):
        somecastfield = models....

class Articles(SomeCommonNameHere):
        somearticlefield = models...

class Faves(models.Model):
        post = models.ForeignKey(SomeCommonNameHere)
        user = models.ForeignKey(User,unique=True)

you can then access the subclass' specific fields by referencing:
        #where fave is an instance of Faves...  
        fave.post.articles.somearticlefield...
             or
        fave.post.casts.somecastfield...

        

You may also want to look at proxy classes.

Checkout
http://docs.djangoproject.com/en/dev/topics/db/models/#multiple-inherita
nce


Will
-----Original Message-----
From: django-users@googlegroups.com
[mailto:django-us...@googlegroups.com] On Behalf Of Anakin
Sent: Tuesday, May 19, 2009 5:29 AM
To: Django users
Subject: Dynamic ForeignKey using or how ?


i want to use 2 model in one foreignkey, i think its dynamic
foreignkey

it means;

i have 2 model named screencasts and articles. and i have a fave
model, for favouriting this model entrys. can i use model dynamicly ?

class Articles(models.Model):
    title = models.CharField(max_length=100)
    body = models.TextField()

class Casts(models.Model):
    title = models.CharField(max_length=100)
    body = models.TextField()

class Faves(models.Model):
    post = models.ForeignKey(****CASTS-OR-ARTICLES****)
    user = models.ForeignKey(User,unique=True)

is it possible ?

thank you


--~--~---------~--~----~------------~-------~--~----~
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