django-forms

getting the user from a admin validation class

故事扮演 提交于 2019-12-24 02:50:12
问题 I am trying to control admin item entry where non-super user accounts can't save a ChannelStatus model input that has a date attribute which is older than 2 days. I need to get the user so that I can check if the request is a reqular or a super user but couldn't achieve this. I have already tried "request.user.is_superuser", "user.is_superuser", "self.user.is_superuser" and "self.request.user.is_superuser" but none seem to work. class ChannelStatusValidForm(forms.ModelForm): class Meta: model

Django form not being submitted

戏子无情 提交于 2019-12-24 02:14:27
问题 I have a Django model/view/form that is rendering correctly in the template, but it is not submitting the data that is input to the database. Any help with this would be greatly appreciated! #models.py from django.db import models from django.forms import ModelForm class UserRegistration(models.Model): user_first = models.CharField(max_length=50) user_last = models.CharField(max_length=50) user_email = models.EmailField() #user_fantasyhost = models.CharField(max_length=50) def __unicode__

Reverse for 'edit' with no arguments not found. 1 pattern(s) tried: ['articles/edit/(?P<pk>[0-9]+)/$']

℡╲_俬逩灬. 提交于 2019-12-24 01:36:18
问题 I am a beginner in Django and now i am developing a blogging application. At the article editing section i got stucked and I dont know why its showing this error. Searched a lot and cant find an answer NoReverseMatch at /articles/edit/2/ Reverse for 'edit' with no arguments not found. 1 pattern(s) tried: ['articles/edit/(?P<pk>[0-9]+)/$'] edit_articles section in views.py @login_required(login_url="/accounts/login/") def edit_articles(request, pk): article = get_object_or_404(Article, id=pk)

Multiple images in django form with multiupload

为君一笑 提交于 2019-12-24 01:17:45
问题 I need to add multiple images in django form to one model. I did a research and for form outside of django I try to setup django-multiupload. My models.py: class Profile(models.Model): ... ... first = models.ImageField("first", upload_to='first') second = models.ImageField("second", upload_to='second') ... In forms.py: class AddForm(forms.ModelForm): first = MultiImageField(min_num=1, max_num=20) second = MultiImageField(min_num=1, max_num=4) In views.py: class UploadView(FormView): template

Django: Class based view can't render crispy form

耗尽温柔 提交于 2019-12-24 01:00:01
问题 Hi Stackoverflow people, I have trouble to render a crispy form with a class based view. Everything worked fine when I used the function based views. As usual I generate forms.py as follows: from django import forms from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout, Div, Submit, HTML, Button, Row, Field from item.models import Item class CreateItemForm(forms.ModelForm): class Meta: model = Item exclude = ('user',) def __init__(self, *args, **kwargs): self

How do i fix this error in my Comments view in my Django app?

假如想象 提交于 2019-12-24 00:45:03
问题 I'm trying to develop an app in Django. At the moment I'm trying to create a comment section for the users to write and submit comments by using a form. I made a template which shows the info of a movie as well as a form through which users can write comments on the film. The problem is that when I write the comment and try to submit it this error shows up : IntegrityError at /myapp2/2/ NOT NULL constraint failed: myapp2_comentario.pelicula_id my Views.py def detallesPelicula(request,

How to manually create a select field from a ModelForm in Django?

泄露秘密 提交于 2019-12-23 22:23:05
问题 I have a ModelForm where one of the field (named creator ) is a ForeignKey , so for {{ form.creator }} Django renders the <select> tag like this: <select id="id_approver" name="approver"> <option selected="selected" value="">---------</option> <option value="1">hobbes3</option> <option value="2">tareqmd</option> <option value="3">bob</option> <option value="4">sam</option> <option value="5">jane</option> </select> But I want to add a onchange event attribute so I can use AJAX later to do

ImportError: cannot import name <model_class>

强颜欢笑 提交于 2019-12-23 21:30:36
问题 I am using forms.ModelChoiceField to have the choice loaded from a specific model entries: from order.models import Region class CheckoutForm(forms.Form): area = forms.ModelChoiceField(queryset=Region.objects.all(),label=("Area")) The problem I am facing is that when importing the class name from the app. I get the error: ImportError: cannot import name Region Please not that from order.models import Region is working when testing it independently in the shell. Any Idea what is causing so?

how to create a dependant drop down using autocomplete light

佐手、 提交于 2019-12-23 20:13:21
问题 I have created a form using Django Model Form and autocomplete_light . I want to filter the suggestions in the drop down list item according to the arguement passed when the class is called. My form is class CamenuForm(autocomplete_light.ModelForm): class Meta: model = Ca_dispensaries_item exclude = ('dispensary',) autocomplete_fields = ('item',) def __init__(self, *args, **kwargs): self.category = kwargs.pop('category', None) super(CamenuForm, self).__init__(*args, **kwargs) self.fields[

Duplicate jquery ui problem

我的梦境 提交于 2019-12-23 20:08:56
问题 I'm working on a Django project. But my problem is on JQuery. I used jquery.formset.js JQuery plugin to add form dynamically in inline_formsets, formset_factories. And this works pretty nice. It duplicates the first row elements with its other decoration tags (like div, span, img..) and adds the new row in the bottom of the table. So the duplicated row can be appeared just like the origin. I also uses jquery ui (datepicker, autocomplete..etc) in my forms. The duplication copies everything,