django-forms

Django formset only adding one form

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 08:15:35
问题 OK, so this is my first time using formsets. I am trying to create a table that I can dynamically add rows to and fill out each row, then submit and have Django put them all in the database. Every time I submit it only adds the first form. File views.py: @main_context_wrapper def bacteriaForm2(request,context): if not request.user.is_authenticated(): #If user isn't authenticated, then just redirect to login return HttpResponseRedirect('/login/') BacteriaFormSet = formset_factory(BacteriaForm)

Change Values of User Model while it has OneToOneField Connection to another model in ModelForms django

你。 提交于 2019-12-13 07:32:04
问题 i have problems with Django ModelForms and here is one of them i wanna have some extra fields for User Model in Django and so made an CustomeUser Model in models.py models.py class CustomeUser(models.Model): user = models.OneToOneField(User) City = models.ForeignKey(City, on_delete=models.CASCADE, blank=True, null=True) Gender = models.ForeignKey(Gender, null=True, blank=True) DateOfBirth = models.DateField(null=True, blank=True) ProfilePicture = models.ImageField(verbose_name="Profile

Conditionally display a Fieldset with Crispy Forms

ε祈祈猫儿з 提交于 2019-12-13 07:26:13
问题 I want to do something simple while using Crispy Forms; I want show a Fieldset only if the user belongs to the staff group. This is easily solved in a standard templates like this: {% if user.is_staff %} show extra stuff {% endif %} Maybe I missed something in the manual, but I don't see how I can just inject a template tag like "{% if user.is_staff %}" into the crispy form Layout. It would be ideal for my use case if I could something like the following where I use a fictitious 'Djangotag'

Class Based Views (CBV), CreateView and request.user with a many-to-many relation

牧云@^-^@ 提交于 2019-12-13 07:26:05
问题 Based on the examples from https://docs.djangoproject.com/en/1.11/topics/class-based-views/generic-editing/#models-and-request-user - but with a many-to-many relation instead of a foreign key relation: models.py from django.contrib.auth.models import User from django.db import models class Author(models.Model): name = models.CharField(max_length=200) owners = models.ManyToManyField(User, related_name='owners_') views.py from django.views.generic.edit import CreateView from myapp.models import

performing different functionality on modelform buttons django

倾然丶 夕夏残阳落幕 提交于 2019-12-13 07:24:05
问题 I have a modelform with 2 buttons and i want to perform different functionality on them. My modelform: class jobpostForm(ModelForm): class Meta: model = jobpost fields = ('job_title','job_type','job_location','job_description','start_date','end_date','country','how_to_apply') widgets = { 'job_type':RadioSelect(), 'job_location':TextInput(attrs={'size':'70'}), 'job_description':Textarea(attrs={'cols':200, 'rows':10}), 'start_date':TextInput(attrs={ 'class': 'datepicker', 'data-date-format':

MyModelForm' object has no attribute 'user using django

喜你入骨 提交于 2019-12-13 07:06:11
问题 i want to create i simple django image processing .first i have create correct a django auth and multi upload images in my app. now i want the user can select one self image from a list django form where i create and that image i get for my processing.i create something but not work. i take that error : 'MyModelForm' object has no attribute 'user' here the code : views.py @login_required(login_url="login/") def myview(request): Myf = MyModelForm(request.user,request.POST) return render

Django save only first form of formset

不打扰是莪最后的温柔 提交于 2019-12-13 06:29:11
问题 I've looked through every similar question (and tried them), but still couldn't find answer. I have two models: class Project(models.Model): author = models.ForeignKey(settings.AUTH_USER_MODEL, default=1) name = models.CharField(max_length=120, verbose_name = "Название проекта") url = models.URLField(max_length=120, unique=True, verbose_name = "Полный адрес сайта") robots_length = models.CharField(max_length=5, default=0) updated = models.DateTimeField(auto_now=True, auto_now_add=False)

Django request.session does not resolve

喜你入骨 提交于 2019-12-13 06:17:07
问题 I have a ManyToMany relation between 2 of my models in the same app. This looks like following: class Event(models.Model): eventID = models.CharField(deafult = random_eventID) signal = models.ManyToManyField(Signal) .... .... Now, in my Form (using ModelForm) my eventID field is already populated with the eventID every time i refresh the page (because it gets a new random_eventID every time i refresh the page). This way when, in my forms i select to add a new signal (I want to be able to add

Change query parameter via select

半城伤御伤魂 提交于 2019-12-13 06:01:59
问题 I have a model Dish and a model Menu: class MenuItem(models.Model): dish_name=models.TextField(unique=False) price=models.DecimalField(max_digits=5,decimal_places=2,blank=True) main_ngredient=models.TextField(unique=False) course=models.CharField(max_length=100) menu=models.ForeignKey('Menu') def __unicode__(self): return name class Menu(models.Model): restaurant=models.TextField(unique=False) year=models.IntegerField(unique=False) location=models.TextField(unique=False) status=models

How to upload multiple images using modelformset - Django

こ雲淡風輕ζ 提交于 2019-12-13 05:52:57
问题 I am trying to create a system which allows a user to be able to add a new Vegetable object, upload a thumbnail and multiple images and files - all from the AddVegetable page, and be able to output this easily as the vegetable types are filtered to display on different pages I'm trying to achieve this with the code below but it won't work and I cant figure out why exactly, as it stands I'm getting a KeyError 'image', but I don't know why. I am going about this the right way at all? I am