Hi again! Is there a way to add multiple models to a class view (django)? I'm trying to add two models to a group update view so that when a new group is created the user gets added to the groups userList. Attached is pictures from the model and views (the relevent stuff). For the AllgroupsCreateView class I want to be able to use two models: model = Allgroups, userlist So that when the new group is created the author of the new group can be added to the userlist in the same view. Any ideas? Thanks! (There have been alot of other problems on here that are more complicated than this one. All I want to know is if there is a way to have more than one model for a class view.  Please do not keep flagging.)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hi again! Is there a way to add multiple models to a class view (django)? I'm trying to add two models to a group update view so that when a new group is created the user gets added to the groups userList. Attached is pictures from the model and views (the relevent stuff).

For the AllgroupsCreateView class I want to be able to use two models:

model = Allgroups, userlist

So that when the new group is created the author of the new group can be added to the userlist in the same view.

Any ideas? Thanks!

(There have been alot of other problems on here that are more complicated than this one. All I want to know is if there is a way to have more than one model for a class view.  Please do not keep flagging.)

allgroupslviews.py
from .models import Allgroups, userlist,
class AllgroupsCreateView(LoginRequiredMixin, CreateView):
model = Allgroups
template_name = 'allgroups_new.html'
fields =
('title', 'body','private',)
login_url = 'login'
def form_valid(self, form):
form.instance.author = self.request.user
return super(). form_valid(form)
class userlistUpdateView(CreateView):
model = userlist
fields = ('user','allgroups',)
template_name = 'userlist_update.html'
success_url = reverse_lazy('allgroups_list')
def test_func (self):
obj = self.get_object ()
return obj.author == self.request.user
Transcribed Image Text:allgroupslviews.py from .models import Allgroups, userlist, class AllgroupsCreateView(LoginRequiredMixin, CreateView): model = Allgroups template_name = 'allgroups_new.html' fields = ('title', 'body','private',) login_url = 'login' def form_valid(self, form): form.instance.author = self.request.user return super(). form_valid(form) class userlistUpdateView(CreateView): model = userlist fields = ('user','allgroups',) template_name = 'userlist_update.html' success_url = reverse_lazy('allgroups_list') def test_func (self): obj = self.get_object () return obj.author == self.request.user
allgroupsimodels.py
class Allgroups (models.Model):
title = models.CharField(max_length=255)
body = models.TextField()
date = models.DateTimeField(auto_now_add=True)
private = models.BooleanField(default=False)
discussion = models.Charfield(max_length=255)
author = models.Foreignkey(
get_user_model(),
on_delete=models.CASCADE,
def _str_(self):
return self.title
def get_absolute_ur1(self):
return reverse('allgroups_detail', args=[str(self.id)])
class userlist(models.Model):
allgroups = models.Foreignkey(
Allgroups,
on_delete=models.CASCADE,
related_name = 'userList',
user = models.Foreignkey(
get_user_model(),
on_delete=models.CASCADE,
def _str_(self):
return str(self.user)
Transcribed Image Text:allgroupsimodels.py class Allgroups (models.Model): title = models.CharField(max_length=255) body = models.TextField() date = models.DateTimeField(auto_now_add=True) private = models.BooleanField(default=False) discussion = models.Charfield(max_length=255) author = models.Foreignkey( get_user_model(), on_delete=models.CASCADE, def _str_(self): return self.title def get_absolute_ur1(self): return reverse('allgroups_detail', args=[str(self.id)]) class userlist(models.Model): allgroups = models.Foreignkey( Allgroups, on_delete=models.CASCADE, related_name = 'userList', user = models.Foreignkey( get_user_model(), on_delete=models.CASCADE, def _str_(self): return str(self.user)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Multithreading Methods
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education