I wish you a good start to the week and I take this opportunity to ask a question about the implementation of my model in django 1.9 using mysql:
I have a catalog of authors and each one has a unique id, each author participates in one or several works, and additionally, there is a field of order of mention within the work.
Initially I thought that the "order" field (of order of appearance in the work) should be in the Authors table, something like this:
class Autor(models.Model):
orden = models.CharField(max_length=2)
nombre = models.CharField(max_length=40)
primer_apellido = models.CharField(max_length=40)
segundo_apellido = models.CharField(max_length=40,blank=True)
correo = models.EmailField(blank=True)
institucion = models.CharField(max_length=200)
class Meta:
ordering = ["primer_apellido"]
verbose_name_plural ="Autores"
def __str__(self):
return '%s %s %s' %(self.nombre, self.primer_apellido, self.segundo_apellido)
but then I realized that the one you put in the authors table, the order in which it appears in a job, will not allow me to use the same author's record in another job, since it might have another order within the second work -order, refers rather to the position in which his name is mentioned within the work, the main author is 1, the second author has the order 2, etc .-
I know I need an intermediate table so that the authors, the works and the order thereof are related, so my model would be something like this:
class Contribucion(models.Model):
autores = models.ForeignKey(Autor)
orden_autor = models.ForeignKey(Autor.orden)
trabajo = models.ForeignKey(Trabajo)
But when doing check
from manage.py, it returns the error: AttributeError: type object 'Autor' has no attribute 'orden'
The question is: how could the order field be included in the model so that when retrieving the records from the table, the order of mention of the authors does so by establishing an ascending order with that field.
Thank you very much in advance for your support.
Gustavo.