django-forms

How to get a queryset from many to many field

How to get a queryset from many to many field Question: I have this model and i want to retrieve all the "members" as queryset class Team(models.Model): name = models.CharField(max_length=120) owner = models.ForeignKey(User, on_delete=models.CASCADE, related_name=’owner’) members = models.ManyToManyField(User, related_name=’members’) # <— I tried this but its not working Team.objects.all()[‘members’] # and Team.members.all() Asked By: laxmymow …

Total answers: 2

Creating a team of users with jobs

Creating a team of users with jobs Question: I want to make a model where users can create a team of users, and in these teams add the job that they did and choose recipient of the job(that is the member of this team) that they did it for. I don’t how to create a …

Total answers: 1

Django form with m2m relationship not saving

Django form with m2m relationship not saving Question: I have a form where I want request.user to populate as little as possible and rely on the views to populate other fields automatically. As a result, some of these fields are not rendered on the form. The code in my view seems to work fine for …

Total answers: 1

How to make forms which users can add | Django

How to make forms which users can add | Django Question: I want to make something like google forms which users can make themselfs. I want just simple html string forms which can reveal answer and check is it right instantly. No matter how users will create forms, but only using webpage. Without additional connecton …

Total answers: 1

Django forms – limiting options from fields based on the answer of another field

Django forms – limiting options from fields based on the answer of another field Question: I have a Django form that receives entries from the users with information on a surgical procedure. Each Procedure will have only one (surgical) Technique and only one Diagnosis. Each Technique may be related to a limited number of Diagnosis, …

Total answers: 2

Image field form not validating

Image field form not validating Question: I have this view with two forms. def anunciocreateview(request): anuncio_form = AnuncioForm(request.POST or None) producto_form = ProductoForm(request.POST or None) if request.method == "POST": if all([anuncio_form.is_valid(), producto_form.is_valid(), imagen_form.is_valid()]): anuncio = anuncio_form.save(commit=False) anuncio.anunciante = request.user anuncio.save() producto = producto_form.save(commit=False) producto.anuncio = anuncio producto.save() return HttpResponse(status=204, headers={‘HX-Trigger’ : ‘eventsListChanged’}) else: anuncio_form = …

Total answers: 1

Django form validation

Django form validation Question: Is there an easier way to write validation for each item in a form? Maybe embed them in model declaration itself? class InfoUpdateForm(forms.ModelForm): class Meta: model = Profile fields = [ ‘first_name’, ‘middle_name’, ‘last_name’ ] def clean(self): cleaned_data = super().clean() first_name = cleaned_data.get(‘first_name’) if not str(first_name).isalnum(): self._errors[‘first_name’] = self.error_class([‘First name should …

Total answers: 1

post action drops part of the url in django app

post action drops part of the url in django app Question: I’m building my first ecommerce app, while attempting to gain more skills in Django. I have a form problem, where I am either adding a product, or editing one, using the same Template. My problem is where the action call drops part of the …

Total answers: 3

How to autofill user and slug fields in django form

How to autofill user and slug fields in django form Question: I need two of the three form fields to be filled in automatically before submitting to the database. Slug is supposed to be filled based on test_name, and user have to be filled based on data about the current user. Now I can submit …

Total answers: 1

Django Admin doesn't recognise blank=True in model

Django Admin doesn't recognise blank=True in model Question: When I try to edit a user (using a custom UserChangeForm) in the Django admin panel, validation insists that fields I have set blank=True in the model are required. I don’t know where to begin solving this; I had the same issue with the CustomUserCreationForm but reverted …

Total answers: 1