django-views

Django CreateUpdateView implementation in the django template

只愿长相守 提交于 2021-01-29 17:59:51
问题 I am very new to django Class based views, trying to integrate it with my existing project. My goal is to use same Class based view to Create and Update student application form. I am trying to integrate CreateUpdateView from the @scubabuddha's answer from the solution. views.py from createupdateview import CreateUpdateView class StudentView(CreateUpdateView): template_name="admission.html" Model = Student form_class = StudentForm def get(self, request, *args, **kwargs): return self.post

Django IntegrityError: null value in column “interestreceiver_id” of relation “HomeFeed_interest” violates not-null constraint

时光毁灭记忆、已成空白 提交于 2021-01-29 17:13:07
问题 Django : Why is my submit interest form not submitted because of an integrity error issue? Did I write my view or template wrongly? How should I solve this error as i've never encountered before. i searched on this website and saw some profile examples but mine is blog post and i dont really understand how their change could solve the error.. should it be 'obj.interestsender=user' and not 'object. interestreceiver=user' and whether i also need 'obj.interestreceiver=blog_post.author' in the

django_select2 - limit the returned text to a specific field in module

狂风中的少年 提交于 2021-01-29 14:39:09
问题 I am using django_select2 in my application. I would like to search and display only according to one field of a model. models.py: class Venue(models.Model): venue_name = models.CharField(max_length=50) venue_city = models.CharField(max_length=50) venue_country = models.CharField(max_length=50) def __str__(self): return f"{self.venue_name}, {self.venue_city}, {self.venue_country}" forms.py: from django import forms from .models import from django_select2 import forms as s2forms class

How to display Foreign key Data in Django view page?

て烟熏妆下的殇ゞ 提交于 2021-01-29 14:01:33
问题 i have relation between Project and ProjectFloorPlan , and i want to display ProjectFloorPlan data in my template. Please let me know how i can display the ForeignKey data in my template. Here is my models.py file... class Project(models.Model): name=models.CharField(max_length=225) slug=models.SlugField(null=True, unique=True) def __str__(self): return self.name class ProjectFloorPlan(models.Model): project=models.ForeignKey('Project', related_name='projectfloorplan', on_delete=models

Extraction datas from forms

随声附和 提交于 2021-01-29 13:46:54
问题 I've just start to learn Django and now I'm trying understand how to insert datas in db, how to work with datas from templates and ect. My question is about extracting datas from form(Meta class) in template. Here is my code: model class Worker(models.Model): POSITION_SHOICE = ( ('MANAGER', 'MANAGER'), ('developer', 'DEVELOPER'), ('teamlead', 'TEAMLEAD'), ('pm', 'PM'), ('hr', 'HR'), ) f_name = models.CharField(max_length=50) s_name = models.CharField(max_length=50) position = models.CharField

Django : How to write Django Group by and where Condition?

放肆的年华 提交于 2021-01-29 13:24:40
问题 I have Django Model with five fields and I mention two fields in serializer class.I need to perform group by and where ClosingStock>0 condition. I have tried with this query but am not getting output. StoreClosingStock.objects.filter(CLOSING_STOCK__gte="0").values('ITEM_CODE','CLOSING_STOCK') I have implemented the same query in mysql its working fine .I want the same output in Django Views.py class StoreClosingViewset(viewsets.ModelViewSet): serializer_class = StoreClosingStockSerializer

Django Error: ValueError at /new_bid/1 Cannot assign “1”: “Bid.listingid” must be a “Listings” instance

放肆的年华 提交于 2021-01-29 09:33:16
问题 I am getting the error: ValueError at /new_bid/1 Cannot assign "1": "Bid.listingid" must be a "Listings" instance." I am still learning about Foreign Keys so I may have used it wrong? I'm also using 'listingid' in both the models 'Listings' and 'Bid.' I'm wondering if this is part of the issue, but it makes sense to have both to me. I am just learning about how 'self' works also, so I think part of the problem is in the Listings model at the very bottom: In the Listings model if I do: return

Django and Chart.js Not Rendering Graph Correctly

試著忘記壹切 提交于 2021-01-29 09:01:23
问题 So I spent the weekend testing and searching SO and finally got Django and Chart.js working. Kind of. It renders the graph but the data is not correct. When I loop through the object, the results are not what I would expect. Maybe I'm blind from staring at this all weekend. Would appreciate any pointers. Here are my views... class ChartView(LoginRequiredMixin, TemplateView): template_name = 'Books/chart.html' def get_context_data(self, **kwargs): context = super(ChartView, self).get_context

Main picture missing in djangocms-light-gallery

不问归期 提交于 2021-01-29 08:49:47
问题 I encountered a problem using the djangocms-light-gallery from https://pypi.org/project/djangocms-light-gallery/. After following the installation steps described in the above posted link, everything seemed to work as expected at first sight. The plugin appears as "Light Gallery" among the other components, thumbnails are displayed correctly, the gallery view opens, etc. The only thing that is missing is the main picture in gallery view. I have no idea how to fix this.. I receive the

How to handle a POST request from a Django form loaded via a custom template tag?

馋奶兔 提交于 2021-01-29 08:45:48
问题 I added a Django form to my Bootstrap nav bar to be included on every page, and it renders as it should with the appropriate values. The form was added using an inclusion_tag. However, I'm now at a loss as to how to handle the request from the form. Upon submission, whichever page the user was on should reload with updated content from the form submission. For more context, see my earlier question: How to place a django form in a nav bar so that it appears on every page? 回答1: Answering my own