django-views

Django Rest Framework - “detail”: “Not found.”

▼魔方 西西 提交于 2019-12-08 14:48:31
问题 Hi when doing this request: groups/25010a31-fc5b-47c8-9c5c-d740e5743f52/members/4/ - I get "detail": "Not found" However, if you look in the queryset I have printed the Groupmember instance and this ends up printing out that particular instance so clearly it exists? View: class MemberDetail(mixins.RetrieveModelMixin, mixins.DestroyModelMixin, mixins.UpdateModelMixin, generics.GenericAPIView): serializer_class = GroupMembersSerializer lookup_field = "user_id" lookup_url_kwarg = "uuid" def get

How to deal with a MultiObjectsReturned Error

纵然是瞬间 提交于 2019-12-08 13:22:25
问题 I have come across this error as i try to load a page. get() returned more than one Item -- it returned 2! Lookup parameters were {} here is the view that renders the page: def get_category(request): categories = Category.objects.all().prefetch_related('item') # need to evaluate the HTTP method if request.method == 'POST': # add to order..create the bound form postdata = request.POST.copy() form = forms.PartialOrderItemForm(request.POST,postdata) # check validation of posted data if form.is

Primary key check in django

怎甘沉沦 提交于 2019-12-08 12:54:18
问题 I have this custom primary key in a model: class Personal(models.Model): name = models.CharField(max_length=20,primary_key=True) email = models.EmailField(blank=True,null=True) Now the thing i m not getting is, how can i create my view so that no duplicate record is entered? I searched this over online, but could find any technique to get the view created. here is the code for views def uregister(request): errors = [] if request.method == 'POST': if not request.POST.get('txtName', ''): errors

cell color Django-Tables2

[亡魂溺海] 提交于 2019-12-08 12:02:49
问题 Question: Where do I edit my django code to change the background color of individual cells based on business logic? In my views.py I have logic that captures the max value of column 'pts': def show_teams(request): reg = Teamoffense.objects.filter(~Q(rk='RK')) pts = Teamoffense.objects.filter(~Q(pts='PTS')).values('pts') seq = [item['pts'] for item in pts] maxseq = max(seq) table = SimpleTable(reg) table_to_report = RequestConfig(request).configure(table) if table_to_report: return create

How to create Dependent dropdown in Django forms?

爱⌒轻易说出口 提交于 2019-12-08 11:33:39
问题 I want to create dependent dropdowns. For example, if someone selects book from the first dropdown, second dropdown should have chapter listed under that book. I have achieved it using HTML / Jquery / AJAX. But i am now interested to achieve same using Django forms. If anyone have idea, please share it. Thank you in advance. 回答1: If you are not afraid of adding dependencies: django-select2 has an implementation of chained selects, which can be configured using the django form API. Example

How to redirect in a Generic View

二次信任 提交于 2019-12-08 11:16:59
问题 I am using a generic view to render my blog post item: class PostUpdateView(UpdateView, LoginRequiredMixin): model = Post # etc I have a model method on the Post model that results in a boolean True or False : @property def can_edit(self): return self.displays_set.count() == 0 If can_edit is False for the Post object, how can I refactor the view to redirect from my UpdateView to a different DetailView ? 回答1: Override the dispatch method, and check obj.can_edit there. That way the object will

Django — Redirecting Views with Parameters

放肆的年华 提交于 2019-12-08 10:45:35
问题 In the Django app I am building I would like to have the user creation process go as follows: As user signs up, if valid is then redirected to create a LIST object, and if valid is then redirected to what will be a dashboard for the LIST object just created. My views.py are as follows: def user_signup(request): if request.method == 'POST': form = forms.UserSignupForm(data=request.POST) if form.is_valid(): user = form.save() g = Group.objects.get(name='test_group') g.user_set.add(user) # log

Dynamic Chart using django and Chart.js

為{幸葍}努か 提交于 2019-12-08 10:37:57
问题 Hi Guys I have a question or a request that I do not really know how to achieve. I am using chart.js in my django app in order to retrieve data and render it in great graphs. I followed the tutorial and I managed to make it work but I would like my chart to add dataset dynamically. I would like to create a radar chart showing data from a team of x numbers. I created a test for a team of 2 people manually HTML/Script: labels_list = data.labels info_data1 = data.data1 info_data1 = data.data2

Replacing text with variables

[亡魂溺海] 提交于 2019-12-08 10:28:11
问题 I have to send out letters to certain clients and I have a standard letter that I need to use. I want to replace some of the text inside the body of the message with variables. Here is my maturity_letter models.py class MaturityLetter(models.Model): default = models.BooleanField(default=False, blank=True) body = models.TextField(blank=True) footer = models.TextField(blank=True) Now the body has a value of this: Dear [primary-firstname], AN IMPORTANT REMINDER… You have a [product] that is

How to create an BytesIO img and pass to template

混江龙づ霸主 提交于 2019-12-08 10:26:45
问题 AIM I am attempting to: Create a histogram, Store it temporary memory, Pass the image to the template. I am having trouble with Step 3 above. I suspect that I am making a simple and fundamental error in relation to passing the context data to the template. ERROR HTML is rendering with a broken image tag. CODE Views.py class SearchResultsView(DetailView): ... def get(self, request, *args, **kwargs): self.get_histogram(request) return super(SearchResultsView, self).get(request, *args, **kwargs)