django-views

Django - ModelForm Create or Update? [duplicate]

被刻印的时光 ゝ 提交于 2020-01-09 09:07:27
问题 This question already has answers here : How to update an object from edit form in Django? (2 answers) Closed 3 years ago . I need to have a form that allows the creation or addition of sessions on a planning Model class Session(models.Model): tutor = models.ForeignKey(User) start_time = models.DateTimeField() end_time = models.DateTimeField() Form class SessionForm(forms.ModelForm): class Meta: model = Session exclude = ['tutor'] View to render the form def editor(request): if request.method

Django - ModelForm Create or Update? [duplicate]

纵饮孤独 提交于 2020-01-09 09:03:24
问题 This question already has answers here : How to update an object from edit form in Django? (2 answers) Closed 3 years ago . I need to have a form that allows the creation or addition of sessions on a planning Model class Session(models.Model): tutor = models.ForeignKey(User) start_time = models.DateTimeField() end_time = models.DateTimeField() Form class SessionForm(forms.ModelForm): class Meta: model = Session exclude = ['tutor'] View to render the form def editor(request): if request.method

Django — Conditional Login Redirect

别说谁变了你拦得住时间么 提交于 2020-01-09 04:55:06
问题 I am working on a Django application that will have two types of users: Admins and Users. Both are groups in my project, and depending on which group the individual logging in belongs to I'd like to redirect them to separate pages. Right now I have this in my settings.py LOGIN_REDIRECT_URL = 'admin_list' This redirects all users who sign in to 'admin_list', but the view is only accessible to members of the Admins group -- otherwise it returns a 403. As for the login view itself, I'm just

error while submitting data in the form django

风流意气都作罢 提交于 2020-01-07 04:48:24
问题 I am trying to insert data into db it throws below error,can any please fix this. enter code here model.py from django.db import models # Create your models here. class Profile(models.Model): name = models.CharField(max_length=50, primary_key=True) assign = models.CharField(max_length=50) doj = models.DateField() class Meta: db_table= 'profile' def __unicode__(self): return u'%s' % (self.name) class working(models.Model): w_name =models.ForeignKey(Profile, db_column='w_name') monday = models

Save m2m in FormView django

无人久伴 提交于 2020-01-07 04:22:07
问题 I'm trying to save a m2m field in a FormView . Here is my code: class ProductorPropietarioView(FormView): form_class = FormPropietario success_url = '/' template_name = 'productores/propietario.html' def form_valid(self,form): form.save(commit=False) form.save() form.save_m2m() return super(ProductorPropietarioView,self).form_valid(form) models.py class Persona(models.Model): predio = models.ForeignKey(InfoPredioGeneral,related_name='predio+') rol = models.ManyToManyField(RolPersona) tipo

FormView CBV change ModelForm per request

自闭症网瘾萝莉.ら 提交于 2020-01-07 01:59:44
问题 I am trying to build a Wizard for populating data in to DataBase. I try the session.Wizard with out success plus I don't think this is what ti need. correct me if I am wrong. so basically my database have some tables which needs to be fill, because of the joints need to be done, I wanted to make a nice wizard which takes you along the way. so I have a base template which would have steps, sometimes there would be no need in creating a new data if exists all ready. so I have made a display of

Different implementations for Autocomplete-light

*爱你&永不变心* 提交于 2020-01-06 20:19:28
问题 I was able to implement the autocomplete-light function using a class based view format: class UserAccountsUpdate(UpdateView): context_object_name = 'variable_used_in `add_user_accounts.html`' form_class = AddUserAccountsForm template_name = 'add_user_accounts.html' def add_user_institution_details(request): ###code### With this form: class AddUserAccountsForm(autocomplete_light.ModelForm): required_css_class = 'required' name = forms.CharField( required=True, widget=autocomplete_light

Unable to link Blog Posts to Specific Category Django

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-06 20:16:50
问题 I used Tango with Django to create a database containing categories, and I used the Django Girls tutorial to add a blog to the database. Both are working fine, but I have been having trouble linking each blog post to its respective category. Right now, all posts go to my post_list.html page. If I were doing this from scratch, I would add a new view, add a new template, add a url mapping, and then add a link from the category page. I also am aware that I need to edit my blog post model to

Different implementations for Autocomplete-light

只谈情不闲聊 提交于 2020-01-06 20:16:36
问题 I was able to implement the autocomplete-light function using a class based view format: class UserAccountsUpdate(UpdateView): context_object_name = 'variable_used_in `add_user_accounts.html`' form_class = AddUserAccountsForm template_name = 'add_user_accounts.html' def add_user_institution_details(request): ###code### With this form: class AddUserAccountsForm(autocomplete_light.ModelForm): required_css_class = 'required' name = forms.CharField( required=True, widget=autocomplete_light

Manager isn't accessible via (…) instances

夙愿已清 提交于 2020-01-06 20:03:18
问题 I have two tables namely Stuff and Boss. Based on the slug(user_type) from the user, I define which table is going to be used. def Person_info(request,user_type): if user_type=="Staff": item=Staff() elif user_type=="Boss": item=Boss() ................. Then, I need to get the last id for item from its table. But, I am having "Manager isn't accessible via Staff instances" When I try to get the last id of Staff table. How can I bypass this problem ? 回答1: You are querying using the instance,