Order in many to many relation in Django model
Posted
by Pietro Speroni
on Stack Overflow
See other posts from Stack Overflow
or by Pietro Speroni
Published on 2010-05-23T19:21:22Z
Indexed on
2010/05/23
20:01 UTC
Read the original article
Hit count: 333
I am writing a small website to store the papers I have written. The relation papers<-> author is important, but the order of the name of the authors (which one is First Author, which one is second order, and so on) is also important.
I am just learning Django so I don't know much. In any case so far I have done:
from django.db import models
class author(models.Model):
Name = models.CharField(max_length=60)
URLField = models.URLField(verify_exists=True, null=True, blank=True)
def __unicode__(self):
return self.Name
class topic(models.Model):
TopicName = models.CharField(max_length=60)
def __unicode__(self):
return self.TopicName
class publication(models.Model):
Title = models.CharField(max_length=100)
Authors = models.ManyToManyField(author, null=True, blank=True)
Content = models.TextField()
Notes = models.TextField(blank=True)
Abstract = models.TextField(blank=True)
pub_date = models.DateField('date published')
TimeInsertion = models.DateTimeField(auto_now=True)
URLField = models.URLField(verify_exists=True,null=True, blank=True)
Topic = models.ManyToManyField(topic, null=True, blank=True)
def __unicode__(self):
return self.Title
This work fine in the sense that I now can define who the authors are. But I cannot order them. How should I do that?
Of course I could add a series of relations: first author, second author,... but it would be ugly, and would not be flexible. Any better idea?
Thanks
© Stack Overflow or respective owner