django-class-based-views

Using formsets for my fileupload does not work when doing an update class based view only on create in django

岁酱吖の 提交于 2021-01-06 03:48:12
问题 I have used as many examples online as I could cobble together in an attempt to get my two simple models to have the ability to do an inline formset allowing me to add many files to a technial drawing. This is not working, I can only add one file for the Create and the update only updates the Technical_Entry model, not a file...which in of itself acts funny. The UI ona create shows one spot to add a file, then save the entire record and its child record. That works. The update, the UI shows

How to correctly use Django reverse FK lookup to show instances of the child model in CBV

ぃ、小莉子 提交于 2020-12-15 07:02:12
问题 I have two models, field of one of them pointing to the other as shown below: class Group(models.Model): group_company_id = models.CharField(primary_key=True, ...) class Company(models.Model): company_id = models.CharField(primary_key=True, ...) group_company = models.ForeignKey(Group, related_name="related_grp_company", ...) I am trying to get all the Companies that have been created for a particular Group . So I am trying to get the company_id (and other) values in Djnago UpdateView as a

Django Form Validation on Class Based View

给你一囗甜甜゛ 提交于 2020-08-02 04:21:51
问题 I have a very simple Class Based View: In views.py: class IncidentEdit(UpdateView): model=Incident fields = visible_field_list sucess_url = '/status' works fine as-is. I have associated CreateView , DeleteView , etc. I can create edit and delete records. Now to fine-tune the project, I need to add field validation. My question : Where do I put basic validation code when I have based the view on the 'model=' rather than 'form=' ? I could change everything to use form based views, but the whole

Django _set.all filter not working in template

依然范特西╮ 提交于 2020-07-22 22:03:06
问题 I'm trying to filter a list of objects in my database but I can't get it to work on the template using _set.all . The strange thing is it's something I've done in two other places in my project but I cant see why it isnt working this time. view.py: class GolfMonthlyView(generic.ListView): template_name="monthly_view/golf-monthly-view.html" context_object_name='golf_monthly_view' queryset = GolfMonthlyView.objects.all() def get_context_data(self, **kwargs): context = super(GolfMonthlyView,

Django get_queryset return custom variables

元气小坏坏 提交于 2020-06-29 06:41:06
问题 Using users as an example I am trying to show how many users there are. get_context_data works totally fine but get_queryset does not. I know that it's not set up properly but I've been playing around with it for quite some days and something is just not clicking.. The main goal is to use the Dajngo-Filter form and then be able to get the updated number of user count. I've only found endless documentation on how to show the "list" of users. Which I have done but no documentation on how to

class based view django multiple slugs

末鹿安然 提交于 2020-06-17 06:18:09
问题 I have cbt generic listview I want filtering with two slugs. But slug_url_kwargs only allows to pass single string. How can i update slug_url_kwarg to support multiple slugs? Or what can i do else? So i have this models and view function class SaityProfile(models.Model): user = models.ForeignKey(User, default=0) about = models.CharField(max_length=255, blank=True) name = models.CharField(max_length=255) url = models.CharField(max_length=255, unique=True) def __unicode__(self): return self

Django Class based UpdateView with Form for Multiple Uploaded Files

狂风中的少年 提交于 2020-05-24 04:07:04
问题 I have two questions in regards to the problem I am currently facing: Is it best practice in django to overwrite the post method in the CreateView? If it isn't do you write a form _valid function on the CategoryFullForm or in the CreateView and how would it look? The CreateView currently works great, but want to make sure there isn't a better way to do this. If this is best practice, how would you override the get function in the UpdateView so you would be able to edit the files that relate

Automatically set logged-in user as the author in django using createview and modelform

╄→尐↘猪︶ㄣ 提交于 2020-05-15 19:38:07
问题 I am building a frontend form that allows someone to post an article without accessing the admin. When the user is logged in, I would like for him/her to be able to write an article. Upon saving, I would like that user to automatically be set as the author of the article. I am at an impasse. Any help would be much appreciated. models.py from django.db import models from django.urls import reverse from django.contrib.auth.models import User from django.utils import timezone class Article

Django - How to send a success message using a UpdateView CBV

烈酒焚心 提交于 2020-05-13 04:45:31
问题 (first of all sorry for my bad english) I'm trying to show a message in a UpdateView when the users save the changes! This is my view class NeedUpdateView(UpdateView): model = Need template_name = 'purchases/needs_update_form.html' pk_url_kwarg = 'need_id' success_message = 'List successfully saved!!!!' fields = [ 'detail', ] When you save the app loads the same template! but i like to show a bootstrap alert if save the object! This is code in the template to show the message {% if messages %

Django - How to send a success message using a UpdateView CBV

前提是你 提交于 2020-05-13 04:45:24
问题 (first of all sorry for my bad english) I'm trying to show a message in a UpdateView when the users save the changes! This is my view class NeedUpdateView(UpdateView): model = Need template_name = 'purchases/needs_update_form.html' pk_url_kwarg = 'need_id' success_message = 'List successfully saved!!!!' fields = [ 'detail', ] When you save the app loads the same template! but i like to show a bootstrap alert if save the object! This is code in the template to show the message {% if messages %