Questions tagged [django-templates]

1

votes
1

answer
58

Views

How can I get the current user's group in forms.py in Django?

I have a scenario where i need to pass the logged-in user's groud name and get the list users in that group. forms.py -- in the below code i need to pass the user's group instead of Banglore class UpateTaskMaster(forms.ModelForm): def __init__(self, *args, **kwargs): super(UpateTaskMaster, self).__i...
Mohamed Naveen
1

votes
1

answer
279

Views

DJango-tables2 how do I refresh/update the table on the webpage without hitting refresh button

I followed the DJango-tables2 official tutorial and was able to create data set in the terminal using: Person.objects.bulk_create([Person(name='Jieter'), Person(name='Bradley')]) However, the new data in the table on the website doesn't show up until I hit the refresh button. My question is how the...
szd116
1

votes
2

answer
101

Views

Django Model serving Media Files

I have two models: Packages and Images. Images has many to one relation with Packages. Images table has a foreign key package_id. I have to display the attributes country, price of Packages with one image related to the package. There can be many images related to a single package however, I have to...
Shekhar Khatri
1

votes
0

answer
87

Views

How to use formatvalue filter for field in form template?

In Django templates, we use the filter on value fields such as {{value | formatvalue}} I want to generate my form dynamically like the example below. {% for field in form %} {{ field }} {% endfor %} As you know, the field attribute will be generated as an html element. Is there a way to add a filter...
Harun ERGUL
1

votes
0

answer
49

Views

How to re-increment each id attribute in Formset after deleting a Form in Django?

I currently have a formset rendered to a template, where I do a for loop over it to display each form. I have a button which adds extra forms and I also have a delete button which removes any of the forms. My problem is when I delete one of the middle forms, the incrementing from the formset managem...
David Arce
1

votes
1

answer
27

Views

Widget attribute does not work

I have two forms and a formset. I have given __init__ for both the forms. However in my template only my POBodyForm is rendered with the attributes. Looks like __init__ of POHeaderForm is not working. I am not sure what is the error. Can someone please advise? I have been using the similar __init__...
Thaha
1

votes
1

answer
157

Views

Django Multiple Record Insert CreateView ( not enough values to unpack (expected 2, got 1))

i am getting the following message while saving the record. not enough values to unpack (expected 2, got 1) I am getting a Acquisition ID and attaching qoutations(single or multiple ) and once saving the record the system pops out the error. there is no error if i select the ACQID from createview...
Najeebullah Usmani
1

votes
0

answer
47

Views

django create N number of forms in template

I was wondering if it was possible to write a more generic form to use as a template so that during the render it will create as many forms as necessary? If not how would one write code to create N number of forms, where the number is Dependant on the result of some query set, and also the options i...
noone392
1

votes
1

answer
329

Views

Implementing themes in Django (Custom templates by users)

I want to implement the feature for admins to set custom templates. Like they can place themes or templates in a particular folder relative to the home folder. Each theme may have a folder and some config or preview for example(optional). 1) First I need to figure out how to set custom templates di...
Kotlinboy
1

votes
0

answer
250

Views

My HTML table is with pagination, and I want to download the whole table rather than the current visiable rows

Am new to exporting html table to csv. The code below could export only the current visible page, but I want to be able to download from pages 1 -- 200 for instance at a click of a button. // download html table to csv file function downloadCSV(csv, filename) { var csvFile; var downloadLink; csvFile...
Danny76
1

votes
0

answer
236

Views

How to Upload a text file in django using templateview based view and model based forms

I am new to django and stuck on uploading a simple file. I am using TemplateView as views and model based form. I am stuck here. I have no idea what to do. I am using django 2.0. I have attached the code what I have done so far. setting.py import os BASE_DIR = os.path.dirname(os.path.dirname(os.path...
Arshad
1

votes
0

answer
192

Views

How to determine wagtail Page content type within django template?

The core problem is that handling of wagtail RichTextField and StreamField is radically different in the templates. I'm trying to accomplish something similar to the following: {% with post=post.specific %} {% if post.content_type == 'streamfield' %} {% include_block post.body %} {% else %} {{ post....
NarūnasK
1

votes
1

answer
91

Views

Copy ManyToMany Value

I am currently trying to copy a many-to-many-field from one model to another but running into a bit of trouble. I have been able to create the model fine with a many-to-many-field with a ModelMultipleChoiceField, and the model saves the way I want it to. When I try to copy it to another model, I d...
Steve Smith
1

votes
0

answer
26

Views

How do I display only the non empty or non null fields from a django a model?

I have a model called Address and it has about 7 different fields. The corresponding form for this model is completely optional and the user may fill in either all 7 fields or just 1 field or none of the fields. There are no required fields here. Now, if the user has filled only the city and countr...
DeA
1

votes
2

answer
118

Views

Static language to render images in loop - Upload through Django admin

I uploaded images with admin, but cannot render them in the template. What am I missing? Settings.py STATIC_URL = '/static/' STATIC_DIRS = { os.path.join(BASE_DIR, 'static'), } MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') Models.py class Function(models.Model): name = models.Ch...
1

votes
0

answer
36

Views

Many To Many Field Multiple Users

I'm slowly gaining my knowledge with Django, but this one has me stumped. I am trying to create a form that multiple users need to approve. In doing this, I have created a CreateView with a modelform and that works fine. I have also created an UpdateView, and this works fine as well, with the cav...
Steve Smith
1

votes
1

answer
599

Views

Using Django to create sessions and buttons connecting Products to a shopping cart through templates and views.py

Sorry for the length (Thought the info was relevant), and thank you for helping understand how this works. I'm trying to use sessions and Django templates to add items to shopping cart. I'm fairly new to learning Django and have painstakingly read through a bunch of documentation and Stack Overflow...
juju
1

votes
1

answer
33

Views

Get_absolute_url with ForeignKey doesn't work in Django template

I'm trying to return JsonResponse in Django View: return JsonResponse(render_to_string( 'notifications/notifications_dropdown.html', {'new_notifications': new_notifications}), safe=False) notifications_dropdown.html: {% if new_notifications %} {% for notification in new_notifications %} {{ notificat...
12bogdan03
1

votes
2

answer
44

Views

How to add category to my polls app?

My models.py is class Question(models.Model): question_text = models.CharField(max_length= 100) pub_date = models.DateTimeField('Date Is Published') image = models.ImageField(upload_to='Question_Image', blank=True) def __str__(self): return self.question_text And, I have to add a class 'category' so...
arpan mahatra
1

votes
1

answer
24

Views

How do I display the views output on my template in tabular rows?

I am using Django as my web framework. I have written a views function like this.. to fetch a list of all items under the keys UserId and AccountNum from an AWS DynamoDb table : def dsctbl2(request): dynamodb=boto3.client('dynamodb', region_name='us-west-2') response = dynamodb.scan( TableName='User...
Siddharth Singh
1

votes
1

answer
147

Views

Numerical operation with absulute value in Django

I tried to add three different absolute value in my template but I got always 0. I try to explain it: My values: a=-7 b=8 c=10 I tried this method with Django mathfilter: {{a|abs|add:b|abs|add:c|abs}} I always got 0 because I think the mathfilter can't handle many abs value. Could anyone give me an...
1

votes
0

answer
65

Views

How to print in template something when queryset build with union() changes?

I have two queryset: q1 and q2. I make a union of them with q1.union(q2) Now, when I print in template the queryset with a for loop, how can I print something between the two querysets? Something like: Featured results (q1 forloop) Other results (q2 forloop) Why I thought to use union instead of sep...
user1518217
1

votes
1

answer
72

Views

How to make Python property object human-readable - Rendering it through Django templates

I have this property that should display the total price for each product, and I call it in my views and render it. On the rendered page, it just shows up as How am I supposed to make this human-readable? I know this is really simple, and I can't figure out how. I tried the following within my cart...
juju
1

votes
1

answer
54

Views

how can we query foreign key and get results of objects which are connected to foreign key

How can I can use managers to query my foreign key and then retrieve objects that are connected to foreign key? Here is my models.py: from django.db import models # Create your models here. class BookManager(models.Manager): def title_count(self,keyword): return self.filter(title__icontains=keyword)...
1

votes
0

answer
23

Views

app doesn't work with otree 1.4.4

I have an otree app that works perfectly on my computer, with otree 1.3.1. In this app, I specify several settings variables. One of those is called 'sure', which can take values 0 or 1, and I refer to it in models.py and views.py as self.settings.config['sure']. In my html page, I have several con...
arsik87
1

votes
1

answer
35

Views

dictionary values can't be iterated through using their corresponding keys in django template [duplicate]

This question already has an answer here: Django template how to look up a dictionary value with a variable 6 answers So I have a nested dictionary in the form of the following: data = { server:{'rating':{'class':'good, 'desc':'whatever'}, 'vulnerabilities':{'heartbleed':{'severity':'critical', 'd...
Miind
1

votes
0

answer
49

Views

BooleanField not showing the selected value on Update

In a model I have defined the following field: manager = models.BooleanField(choices=BOOL_TYPE_CHOICES, default=BOOL_TYPE_NO) forms: 'manager': RadioSelectWidget(choices=BOOL_TYPE_CHOICES) const BOOL_TYPE_NO = 0 BOOL_TYPE_YES = 1 BOOL_TYPE_CHOICES = ( (BOOL_TYPE_NO, 'No'), (BOOL_TYPE_YES, 'Yes') ) w...
user3541631
1

votes
0

answer
21

Views

how to handle new button in submit_line.html in django

i already create a class to validating xml file, and i try in actions its work but how i can make the script work in new button i create in submit_line.html this is my admin.py with actions class CrsFileAdmin(admin.ModelAdmin): list_display = ('fi', 'file', 'import_datetime', 'state') readonly_field...
putra
1

votes
1

answer
170

Views

How to compare float variable in django template?

Attendances is a list of float variables. Even when the value is less than 75, the first case is executed. I know that by default the django template see's a variable as a string. I know how to convert the variable to integer by making it {% attendance|add:0 %}, but what do I do when the values are...
Aasif Faizal
1

votes
1

answer
332

Views

Invalid block tag on line 3: 'else'. Did you forget to register or load this tag?

I have my main home template, that I would like to extend one of two sets of headers from but I am getting an error that seems to indicate the else does not work in this statement. I also tried changing to an elif for when user is not logged in and the elif was shown as undefined. These are the firs...
Skyler
1

votes
0

answer
23

Views

View and Template for m2m with Through

In my app i need to store invoices (Invoice) of known products (Product) to calculate points for each seller (User). I'm trying to create form to insert basic invoice data plus inline form with sold products info. To handle it i create model like this: class Product(models.Model): group = models.Cha...
Stanislav Vasko
1

votes
1

answer
461

Views

Django filter queryset in template

I'm still studying in school and still new in Python language & Django framework and I'm trying doing projects to learn the best practice for it. Right now I'm building a project like following : Topics Model => which is user can write a new topic Replies Model => which is user can write a new rep...
dan
1

votes
1

answer
37

Views

styling form render in Django

I'm using Django 2.x I'm using Formset to be able to add multiple records at one. the form is rendered in template file as {{ chapter_questions.as_table }} Which renders template like below which looks ugly. I'm using Bootstrap template to design my template to look like To render template like seco...
Anuj TBE
1

votes
2

answer
481

Views

Custom login URL in django

I am a newbie in django and I was experting different options in Django. I have created a class based view which requires user authentication to view the web page. I am using the inbuilt LoginView. When the url pattern is specified as follows url(r'^login/', auth_views.LoginView.as_view(),name='log...
jibin mathew
1

votes
0

answer
81

Views

Django's jinja like block feature in ejs

I have a node-express project that have several page in it, I use ejs templating engine and currently how I handled base-template is copy-paste the template html to new page (Basically, it's bad) I want to use django's jinja 'block' like feature in ejs, is there that kind of feature in ejs? (I confu...
Hari Anugrah
1

votes
0

answer
35

Views

Marking only a part of string as safe

I want to show user's profile link in comment, i.e u/ali should look like a link to user's profile. but I also don't want to risk marking whole comment as safe because it will make site vulnerable to html injection so my question is this: how to mark safe only a part of a string, instead of marking...
Ali
1

votes
0

answer
44

Views

How to render models choices field to a django template(radio button) and then retrieving the selected radio button data to a model

I want to render choices in the form of radio button in an HTML form from the models of the database in Django. Then after displaying the choices in the form of a radio button, I want to store which radio button was selected and storing it in the models (i.e table of models.py). It will be grateful...
DK_521
1

votes
0

answer
195

Views

comment reply in django (review)

i wrote my own comment system in django, but i dont know if its the proper way to achieve this functionaliy. the comment style is like facebook, so you have one comment and replies associated to that comment. please review my code. models.py class Comment(models.Model): blog = models.ForeignKey(Blog...
john
1

votes
0

answer
279

Views

Django uploading/downloading multiple files

Using Django 2.0 What i'm trying to do is post a link for each file uploaded. But my problem is that when I upload multiple files, the field only takes the last one. So long I have tried this: In my CBV def post(self, request, *args, **kwargs): form_class = self.get_form_class() form = self.get_form...
Loki
1

votes
0

answer
81

Views

Python julian date format

I have a function in django that check for selected date and then convert that date to julian date then it extract data from the database based on the selected date. but i am getting an error: time data 'selected_date' does not match format '%Y-%M-%d' my view.py def sum_asset_fundmanager(reque...
sum

View additional questions