Tuesday, November 26, 2019

Re: Django begginer

Hola Daniel, 
Creo que al no declarar el campo "project" como un atributo (CharField, etc) que pueda interpretar el ORM de Django, no lo detecta al momento de declararlo en el admin.register.
Tal vez te pueda funcionar declarar ese campo "project" de la clase Task, que apunte a la clase Project, con un atributo ForeignKey(Project) creo tendrás acceso a los campos de Project.project & Project.client.
Buena suerte,


El martes, 26 de noviembre de 2019, 6:27:47 (UTC-6), Daniel Almeida escribió:
HI guys I´m trying to make a simple timesheet app, first time I´m programming.
So I have this code where I set in models.py the Client and then I want to have the Project class sync with the Client class.
So for each Client I have a different set of Projects.
Now my problem is in Task class I set the variable project = Project (class) however this is the only field I can´t see on my django site.
What am I doing wrong?

class Client(models.Model):
name = models.CharField(max_length=20)

def __str__(self):
return format(self.name)


class Project(models.Model):
client = models.ForeignKey(Client, on_delete=models.CASCADE)
project = models.CharField(max_length=20)

def __str__(self):
return format(self.project)


class Task(models.Model):
client = models.ForeignKey(Client, on_delete=models.CASCADE)
project = Project
date = models.DateField()
assignment = models.CharField(max_length=200)
hours = models.DecimalField(max_digits=4, decimal_places=2)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0f31fc62-9aec-45ab-a174-a51604067e37%40googlegroups.com.

No comments:

Post a Comment