Django UpdateView and Createview

91 views
Skip to first unread message

Rupam Hazra

unread,
Dec 7, 2018, 1:09:25 PM12/7/18
to Django users
Hi,

I have working in a TaskManagement Sytem where i have project module and technology module.

class ProjectMaster(models.Model):
name=models.CharField(max_length=255,blank=True,null=True)
description=models.CharField(max_length=255,blank=True,null=True)
is_agreement_sent=models.BooleanField(default=False)
is_invoice_create=models.BooleanField(default=False)
is_invoice_sent=models.BooleanField(default=False)
is_paid=models.BooleanField(default=False)
status=models.BooleanField(default=True)
is_deleted=models.BooleanField(default=False)
created_at=models.DateTimeField(auto_now_add=True)
created_by = models.ForeignKey(User, on_delete=models.CASCADE,related_name='createdUser',blank=True,null=True)
updated_at=models.DateTimeField(auto_now_add=True)
updated_by=models.ForeignKey(User, on_delete=models.CASCADE, related_name='UpdUser',blank=True,null=True)
#technology_master = models.ForeignKey(TechnologyMaster, on_delete=models.CASCADE, related_name='technologies', )

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

class TechnologyMaster(models.Model):
#projectmaster = models.ForeignKey(ProjectMaster,on_delete=models.CASCADE)
name=models.CharField(max_length=255,blank=True,null=True)
status = models.BooleanField(default=True)
is_deleted = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
created_by = models.ForeignKey(User, on_delete=models.CASCADE,blank=True, null=True,related_name='created_by')
updated_at = models.DateTimeField(auto_now_add=True)
updated_by = models.ForeignKey(User, on_delete=models.CASCADE,blank=True, null=True,related_name='updated_by')
def __str__(self):
return str(self.id)+'-'+ self.name

Here one functionality is one project has multiple technologies so i have made one mapping table below

class ProjectTechnologyMapping(models.Model):
project_master = models.ForeignKey(ProjectMaster, on_delete=models.CASCADE, related_name='projects')
technology_master = models.ForeignKey(TechnologyMaster, on_delete=models.CASCADE, related_name='technologies')
status = models.BooleanField(default=True)
is_deleted = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
created_by = models.ForeignKey(User, on_delete=models.CASCADE,blank=True,null=True,related_name='pro_tech_created_user')
updated_at = models.DateTimeField(auto_now_add=True)
updated_by = models.ForeignKey(User, on_delete=models.CASCADE,blank=True,null=True,related_name='pro_tech_updated_user')
def __str__(self):
return str(self.id)

So, my question is how add and update using django createview,updateview (generic view) using templates.

Ryan Nowakowski

unread,
Dec 9, 2018, 12:51:55 AM12/9/18
to Rupam Hazra, Django users

Deepak Kumar

unread,
Dec 9, 2018, 12:43:44 PM12/9/18
to Django users
> return str(self.id)+'-'+ self.nameHere one functionality is one project has multiple technologies so i have made one mapping table belowclass ProjectTechnologyMapping(models.Model):
> project_master = models.ForeignKey(ProjectMaster, on_delete=models.CASCADE, related_name='projects')
> technology_master = models.ForeignKey(TechnologyMaster, on_delete=models.CASCADE, related_name='technologies')
> status = models.BooleanField(default=True)
> is_deleted = models.BooleanField(default=False)
> created_at = models.DateTimeField(auto_now_add=True)
> created_by = models.ForeignKey(User, on_delete=models.CASCADE,blank=True,null=True,related_name='pro_tech_created_user')
> updated_at = models.DateTimeField(auto_now_add=True)
> updated_by = models.ForeignKey(User, on_delete=models.CASCADE,blank=True,null=True,related_name='pro_tech_updated_user')
> def __str__(self):
> return str(self.id)So, my question is how add and update using django createview,updateview (generic view) using templates.

Okware Aldo

unread,
Dec 9, 2018, 5:43:04 PM12/9/18
to django...@googlegroups.com
Ryan's suggestion should give you a starting point.

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b0be82da-dca5-4594-9f22-e0c3323adc3b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rupam Hazra

unread,
Dec 10, 2018, 9:34:54 AM12/10/18
to Django users
Hi all,

I know and understand how update view working but in my case how to implement on my case.

Please suggest.;

Sidnei Pereira

unread,
Dec 10, 2018, 12:49:34 PM12/10/18
to Django users
Hi,

I don't know if I got it right , but you want to add/update as many instance of Technologies as you want when creating/updating a Project, right? Like when you use an inline on Django's admin.

For that you could user Django Formsets. Here is simple gist for you to get a feeling of it:


An observation about your models, since you want a Projetct to have many Technologies you don't need a junction table. You could just user a ForeignKey model field on the TechnologyMaster model that refers to ProjectMaster model. The way you doing it know it's is actually a many to many relationship. For a better understanding of it in the context of how Django works with database modeling, see: 


Ryan Nowakowski

unread,
Dec 10, 2018, 2:33:34 PM12/10/18
to Django users
Hrrmmm... that documentation link should've answered most of your
questions. It would be easier to help you if you can say specifically
what you're confused about.
> >> email to django-users...@googlegroups.com <javascript:>.
> >> To post to this group, send email to django...@googlegroups.com
> >> <javascript:>.
> >> Visit this group at https://groups.google.com/group/django-users.
> >> To view this discussion on the web visit
> >> https://groups.google.com/d/msgid/django-users/b0be82da-dca5-4594-9f22-e0c3323adc3b%40googlegroups.com
> >> .
> >> For more options, visit https://groups.google.com/d/optout.
> >>
> >
>
> --
> 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...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fc5e6fe9-3169-4c7e-8aec-dc1880718cda%40googlegroups.com.

Rupam Hazra

unread,
Dec 11, 2018, 12:27:08 PM12/11/18
to Django users
Thanks, it is working....

Sidnei Pereira

unread,
Dec 11, 2018, 1:58:28 PM12/11/18
to Django users
Could you point out what exactly was the problem and how did you solve it? A proper feedback is usually useful for those who were helping or those with the same issue.

Thanks in advance.
Reply all
Reply to author
Forward
0 new messages