On Friday 21 April 2006 08:15, skink wrote: > class MyUser(meta.Model): > name = meta.CharField(maxlength=30) > > def __repr__(self): > return self.name > > class Note(meta.Model): > noteText = meta.CharField(maxlength=100) > writer = meta.ForeignKey(MyUser) > publications = meta.ManyToManyField(MyUser) > > def __repr__(self): > return self.headline > > but i don't know how to: > 1 get list of Notes written by given MyUser (for user1 it'd be > [note1, note2] > 2. for a given Note get list of its readers (for note1 it'd be > [user2, user3], for note2 [user3, user4])
> I think that my model is wrong... > Could anyone point me out how my model would be? class Note(meta.Model): noteText = meta.CharField(maxlength=100) writer = meta.ForeignKey(MyUser, related_name="written_notes") publications = meta.ManyToManyField(MyUser, \ related_name="readable_notes") def __repr__(self): return self.headline related_name is important in this case because you have two relationships to the same model, so you need to be careful about disambiguating the reverse relationship. > 1 get list of Notes written by given MyUser (for user1 it'd be > [note1, note2] user1.get_written_notes_list() > 2. for a given Note get list of its readers (for note1 it'd be > [user2, user3], for note2 [user3, user4]) note1.get_publications_list() (NB - I think 'publications' is named confusingly - 'readers' would be better) My apologies if I made some mistakes - I've been using m-r for a while and forgotten what the syntax was like before... Luke -- "If you're not part of the solution, you're part of the precipitate." (Steven Wright) Luke Plant || L.Plant.98 (at) cantab.net || http://lukeplant.me.uk/ --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---