Django begginer

35 views
Skip to first unread message

Daniel Almeida

unread,
Nov 26, 2019, 7:27:47 AM11/26/19
to Django users
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)

Elijah O. Raji

unread,
Nov 26, 2019, 7:53:55 AM11/26/19
to Django users
What exactly do you want the variable 'project' to do because you did not Include any field with it.

JVALREY JVALREY

unread,
Nov 26, 2019, 8:30:52 PM11/26/19
to Django users
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,

Daniel Almeida

unread,
Nov 27, 2019, 5:30:15 AM11/27/19
to Django users
Thank you guys I set as charfield and will be ok for now.

So maybe u can help me further, this is a timesheet app and I have all set in django admin. I can add and delete data from my table in the administration mode.
Now my question is how can I import this to a html template to be able to add data from there instead of using the admin portal?

So lets say I want to display this table in my index.html file like with a "add/+" and "save" button to add contents to my db:
class TaskAdmin(admin.ModelAdmin):
list_display = ('date', 'client', 'project', 'assignment', 'hours')



Reply all
Reply to author
Forward
0 new messages