Hello everyone,
I'm just starting with django and am trying to figure out the best way
to approach creating a top-level model. My "Item" model would be one
that all other items will extend in some way. By doing this, i'm
hoping to give all entries an owner, some metadata (e.g. timestamp) and
per-entry permissions. My item model currently looks like:
class Item(meta.Model):
pub_date = meta.DateTimeField('Publish Date', auto_now_add=True)
owner = meta.ForeignKey(User)
parent = meta.ForeignKey('self', null=True, blank=True,
related_name='child')
def __repr__(self):
return "%s on %s" % (self.owner, self.pub_date)
class META:
permissions = (
("view_item", "Can view item"),
)
class ItemPermission(meta.Model):
item = meta.ForeignKey(Item)
user = meta.ForeignKey(User)
permission = meta.ForeignKey(Permission)
The first item I want to create is a Note, so my model starts like
this:
class Note(meta.Model):
subject = meta.CharField(maxlength=120, core=True)
text = meta.TextField(core=True)
def __repr__(self):
return self.subject
class META:
admin = meta.Admin()
The problem I run into is how to link an item to my Note model. I've
tried a few things such as extending the Note class:
class Note(Item)
This doesn't work because the item columns are recreated in the
database, not referenced. So, I tried the following:
item = meta.ForeignKey(Item, edit_inline=meta.STACKED
num_in_admin=1)
as well as:
item = meta.OneToOneField(Item, primary_key=True, blank=True)
I learned that the former attempt is wrong since it's the reverse of
what I'm trying to accomplish. Instead of giving me an item form when
I add a note, the Item model gets a note form.
The latter almost works, but I still don't get a way to edit an item
inline.
Currently my two goals are:
- ability to manipulate Item data when viewing a note in the admin
interface
- ability to give each entry user and group permissions (not even
attempted yet).
Any advice is greatly appreciated.
Thanks!
-berto.