List Info

Thread: common model




common model
country flaguser name
United States
2007-03-30 15:34:09
If I have multiple items that I want to use a common model,
is there a
way to do this? currently I have:

class Link(models.Model):
	author = models.ForeignKey(User)
	link = URLField()
	description = TextField(blank=True)
	entry_date = models.DateTimeField(default=datetime.now)

class Picture(models.Model):
	author = models.ForeignKey(User)
	link = URLField()
	description = TextField(blank=True)
	entry_date = models.DateTimeField(default=datetime.now)

class Movie(models.Model):
	author = models.ForeignKey(User)
	link = URLField()
	description = TextField(blank=True)
	entry_date = models.DateTimeField(default=datetime.now)

and what I would like is the fields above to be common. I
will be
adding unique fields to each of these items as well, but
would like to
be able, in the future, to add or remove one of these common
fields
easily.


--~--~---------~--~----~------------~-------~--~----~
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 htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: common model
country flaguser name
Australia
2007-03-30 22:10:17
On Fri, 2007-03-30 at 20:34 +0000, drackett wrote:
> If I have multiple items that I want to use a common
model, is there a
> way to do this? currently I have:
> 
> class Link(models.Model):
> 	author = models.ForeignKey(User)
> 	link = URLField()
> 	description = TextField(blank=True)
> 	entry_date =
models.DateTimeField(default=datetime.now)
> 
> class Picture(models.Model):
> 	author = models.ForeignKey(User)
> 	link = URLField()
> 	description = TextField(blank=True)
> 	entry_date =
models.DateTimeField(default=datetime.now)
> 
> class Movie(models.Model):
> 	author = models.ForeignKey(User)
> 	link = URLField()
> 	description = TextField(blank=True)
> 	entry_date =
models.DateTimeField(default=datetime.now)
> 
> and what I would like is the fields above to be common.
I will be
> adding unique fields to each of these items as well,
but would like to
> be able, in the future, to add or remove one of these
common fields
> easily.

"Real soon now" (before 1.0), model inheritance
will work. Until then,
put the common stuff into it's own model and use a OneToOne
field from
each of the derived models to point to the common stuff.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
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 htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: common model
country flaguser name
United States
2007-03-31 13:03:23
Malcolm,

I'm not the op, but have done what you suggested in
splitting models
and linking with OnetoOne fields in the past.  It worked
perfectly
except for one problem: I couldn't figure out any way to
order search
results by a field in a related model.  I tried everything I
could
think of and asked a bit on irc but with no solution.  Am I
missing
the obvious, or is it even possible?  I'm betting the
former, as
usual, but it would be nice to know!


--~--~---------~--~----~------------~-------~--~----~
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 htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-3]

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