Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Django 3 List View objects not displaying in template with if statement. Please help this Django newbie
I'm trying to create a news site with structure like: Master Archive (contains all daily issues of the news publication) Issue (a new one each day with unique articles) Article (related to one Issue) I'm facing a problem where the articles in an issue are not displaying on a Django template (issue_details.html) that's supposed to simply list all articles that are related to an issue. Any suggestions? I'm new to Django and my approach to this may not be best-practice, but things seem to be working other than this problem. articles/views.py from django.shortcuts import render from django.views.generic import ListView, DetailView from .models import Article class IndexView(ListView): model = Article template_name = 'index.html' class ArticleDetailView(DetailView): model = Article template_name = 'article_detail.html' context = { 'details': Article.body } issues/views.py from django.shortcuts import render, HttpResponse from django.views.generic import ListView from .models import Issue, IssueDetails class IssueView(ListView): model = Issue template_name = 'issues.html' slug_url_kwarg = 'slug' slug_field = 'slug' context = { 'issue_title' } issue_view = IssueView.as_view() # List of Articles in a Issue class IssueDetailsView(ListView): model = IssueDetails template_name = 'issue_details.html' slug_url_kwarg = 'slug' slug_field = 'slug' context = { 'title' } issue_details_view = IssueDetailsView.as_view() def detail(request, slug): q = IssueDetails.objects.filter(slug__iexact = slug) … -
Django CSS Not Loading
I'm having problems with my Django > css its not loading on the page for some reason am I missing something ? I have attached snippets of my current code Settings.py urls.py .html -
why django template stop to working HTML autocomplete?
im using Vs.Code. When ı enable to Django Template, HTML autocomplete doesnt work. I want to work Python and HTML at the same time. How can i solve this problem ? has someone any idea ? -
Using Django Models to assign HTML div through jQuery
for the last few days I've been trying to create a method in jquery using django models and I have found myself to be very out of my depth and would appreciate and explanation I can get. So currently I have a django model that has the following information : name, date, location, semester. I use the first 3 pieces of information in displaying my html, however, I want to use 'semester' to see what div tag my items go into. The semester tag can either return 'Fall' or 'Spring' values is there a way I can use this to assign the components to the correct div. So if semester is Fall then it should go into the div with the id 'fall-races' and if its spring it should go to 'spring-races' Currently I only have a jquery working where I get all the elements and assign it to the other div. Thank you for your help and any possible advice. <div class="flex-column"> <div class="header shadow-lg"> <h1 class="text-center py-3"> Fall Schedule </h1> </div> <div id="fall-races"> {% for race in race %} <div class="regatta-card my-2 mx-2 "> <h2 class="center-text py-2">{{ race.date }}</h2> <h1 class="text-center my-2">{{ race.name }}</h1> <h3 class="text-center mb-3">{{ race.location}}</h3> … -
run complex algorithm in python via django
i'm new with django . I am building a django-based app that presents an optimum solution through linear programming that run on the database data. I wrote the code in Python and have all the data displayed through django. Now, how can i connect them. I have no idea how to run the code. I would appreciate any guidance. -
Accessing Choices Value of PositiveSmallIntegerField in Django Template
I have a model like this: class SomeModeL(Model): MODEL_TYPE = ( (0, 'Type1'), (1, 'Type2'), (2, 'Type3') ) model_type = PositiveSmallIntegerField(choices=MODEL_TYPE) Now, I passed in an instance of the model into context and want to access the model_type, specifically the String, such as 'Type1' So, in the template, i do this: {{ some_model.model_type }} but this returns the integer, not the string. How do I get the string? -
Python / Django - edit render output
I'm new to python and I have the following issue. I have a Counterpart database with two boolean fields that are "is_client" and "is_supplier". When a counterpart is added could be either client or supplier or both. I want to display that if is_client=True c_type = "client", if is_supplier=True c_type = "supplier" and if both are True c_type = "client / supplier" How can I do it in the following function? class CounterpartsListView(ListView): model = Counterpart template_name = "counterparts/view_list.html" context_object_name = "counterparts" def get_queryset(self): c_type = self.kwargs.get("type") if c_type == "suppliers": if Counterpart.objects.filter(is_supplier=True).count() >= 1: return ( Counterpart.objects.filter(is_supplier=True) .order_by("counterpart_name") .extra(select={"Supplier": "is_supplier"}) ) else: return Counterpart.objects.all().order_by("counterpart_name") elif c_type == "customers": if Counterpart.objects.filter(is_client=True).count() >= 1: return ( Counterpart.objects.filter(is_client=True) .order_by("counterpart_name") .extra(select={"Customer": "is_client"}) ) else: return Counterpart.objects.all().order_by("counterpart_name") else: return Counterpart.objects.all().order_by("counterpart_name") this is the html output, how can I add the c_type attribute ? {% for counterpart in counterparts %} <tr> <td>{{ counterpart.counterpart_name }}</td> <td>{{ counterpart.city }}</td> <td>{{ counterpart.country }}</td> <td>{{ counterpart.c_type }}</td> </tr> {% endfor %} Alternatively, I was thinking to change the input method and instead of two separate fields (is_client and is_supplier), have just one called c_type and add an the value (customer or supplier) and in case is both add an … -
How to display comment in a particular post
how do i display comment to a particular post in Django. I have watched lots of tutorials and i can understand that comments can be displayed with ForeignKey to a Post using related_name and id passing throught url. I have been stucked up with this issue, I will be glad if someone here can help me with this, i want to display comments to each particular post without adding a related_name to Model. class Post(models.Model): poster_profile = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE, blank=True,null=True) class Comments (models.Model): user = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE, blank=True,null=True) commented_image = models.ForeignKey(Post, on_delete=models.CASCADE, null=True, blank=True) #i don't want a related_name comment_post = models.TextField() def home_view(request): all_comments = Comments.objects.filter(user=request.user, active=True) posts = Comments.objects.filter(pk__in=all_comments) context = {'posts': posts} return render(request,'home.html', context) #this displays all comments for all post, how do i assign comments to the particular post commented on {% for comment in posts %} <p>{{ comment.comment_post }}</p> {% endfor %} -
Django Bootstrap Carousel wont ride
This is my first project with building a website. I have been following these tutorials. I browsed through the Bootstrap components page and found a Carousel method (slides only) that I wanted to use. I copied and pasted it into my code. The first image shows up which is correct, because it is active, but the Carousel does not slide to the next image. The first code block shows a summed up version. The second block of code is after running python manage.py runserver. The third block of code is when I open the IP address link. I am not sure what I am doing wrong. Any suggestions? Let me know if you need some more information. <!DOCTYPE html> <html lang="en"> <head> <title>AeroTract</title> <meta charset="utf-8" /> {% load static %} <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}" type = "text/css"/> <meta name="viewport" content = "width=device-width, initial-scale=1.0"> <style type="text/css"> html, body { height:100% } </style> </head> <body class="body" style="background-color:#FFF8DC"> <!-- Main page background color --> <div class="container-fluid" style="min-height:95%; "> <!-- Footer Height --> <div class="row"> <div class = "col-sm-2"> </div> <div class="col-sm-8"> <br> <div id="mainCarousel" class="carousel slide" data-ride="carousel"> <div class="carousel-inner"> <div class="carousel-item active"> <img class="d-block w-100" src="{% static 'img/Forestry.png' %}" alt="First slide"> … -
check if value is a url or not in django template
I'm working on a Django project that some of its pictures don't come from the media folder so I wanted to know if there's a way for me to check if the value is a link to use media.poster instead of media.poster.url ? -
TypeError at /create_order/ __str__ returned non-string (type NoneType)
Getting an error when placing a new order.That was working fine before connecting with User in models. When I create a separate user_page view and link Customer model with User(import from django.contrib.auth.models) it gives this error: TypeError at /create_order/ str returned non-string (type NoneType) Code in views @login_required(login_url='login') def user_page(request): orders=Customer.objects.filter(user=request.user) context={'orders':orders} return render(request, 'blog/user_page.html', context) @unauthenticated_user def registration_page(request): if request.method=='POST': form=CreationUserForm(request.POST) if form.is_valid(): user=form.save() group=Group.objects.get(name='customer') user.groups.add(group) Customer.objects.create( user=user, ) return redirect('login') else: form=CreationUserForm() return render(request, 'blog/registration.html', {'form':form}) @login_required(login_url='login') @admin_only def home_page(request): orders=Order.objects.all() customer_data=Customer.objects.all() total_orders=orders.count() pending=Order.objects.filter(status='PENDING') total_pending=pending.count() out = orders.filter(status='OUTFORDELIEVERY') total_out = out.count() delievered = orders.filter(status='DELIEVERED') total_delievered = delievered.count() context={'orders':orders, 'customer_data':customer_data, 'total_orders':total_orders, 'total_pending': total_pending, 'total_out':total_out, 'total_delievered':total_delievered} return render(request, 'blog/home_page.html', context) @login_required(login_url='login') @allowed_users(allowed_roles=['admin']) def product_page(request): return render(request, 'blog/product.html') @login_required(login_url='login') @allowed_users(allowed_roles=['admin']) def customer_page(request, id): customer=Customer.objects.get(id=id) orders=customer.order_set.all() total_orders=orders.count() myFilter=OrderFilter(request.GET, queryset=orders) orders=myFilter.qs context={'customer':customer, 'total_orders':total_orders, 'orders':orders, 'myFilter':myFilter} return render(request, 'blog/customer.html', context) @login_required(login_url='login') def create_order(request): if request.method=='POST': form=CustomerForm(request.POST) if form.is_valid(): form.save() return redirect('/') else: form=CustomerForm() context={'form':form} return render(request, 'blog/new_order.html', context) Code in Models from django.db import models from django.contrib.auth.models import User # Create your models here. class Customer(models.Model): user=models.OneToOneField(User, null=True, on_delete=models.CASCADE) name=models.CharField(max_length=200, null=True) email=models.EmailField() phone=models.IntegerField(null=True) date_created=models.DateTimeField(auto_now_add=True, null=True) def __str__(self): return self.name class Tag(models.Model): name=models.CharField(max_length=200, null=True) def __str__(self): return self.name class Product(models.Model): name=models.CharField(max_length=200, null=True) CATEGORY=( ('INDOOR','INDOOR'), ('OUTDOOR','OUTDOOR') … -
Django/Javascript: How to pass variable to template filter in javascript function?
I am currently passing a template variable in views.py: def home_view(request, *args, **kwargs): if scrape.get_countries().count() == 0 or (timezone.now()-scrape.get_global().last_updated).total_seconds()/3600 > 24: scrape.fetch_api_data() scrape.fetch_time_data2() return render(request, 'home.html', {'all_dates': scrape.get_dates()}) where all_dates is a dictionary. In a javascript function in my home.html, I want to be able to access values from the dictionary using a key variable called code. <script> function create_graph(country, code, dates) { var date = "{{ all_dates|get_item:code|get_item:'05/05/2020'|get_item:'confirmed'}}"; window.alert(date); </script> FYI, get_item is just a simple template filter in another file @register.filter def get_item(dictionary, key): if key: return dictionary.get(key) However, when running the server, I get this error message: VariableDoesNotExist at / Failed lookup for key [code] in [{'True': True, 'False': False, 'None': None}, {}, {}, {'global': <Country: Global>, 'countries': <QuerySet [<Country: Global>, <Country: ALA Aland Islands>, <Country: Afghanistan>, <Country: Albania>, <Country: Algeria>, <Country: American Samoa>, <Country: Andorra>, <Country: Angola>, <Country: Anguilla>, <Country: Antarctica>, <Country: Antigua and Barbuda>, <Country: Argentina>, <Country: Armenia>, <Country: Aruba>, <Country: Australia>, <Country: Austria>, <Country: Azerbaijan>, <Country: Bahamas>, <Country: Bahrain>, <Country: Bangladesh>, '...(remaining elements truncated)...']>, 'all_dates': {'..': {}, 'AX': {}, 'AF': {'05/04/2020': {'confirmed': 2894, 'recovered': 397, 'deaths': 90}, '05/03/2020': {'confirmed': 2704, 'recovered': 345, 'deaths': 85}, '05/02/2020': {'confirmed': 2469, 'recovered': 331, 'deaths': 72}, '05/01/2020': {'confirmed': 2335, 'recovered': … -
Yet another No Reverse Match
I have impletmented the detailview with views.py this afternoon. I have a model with the pk set as a UUID. the URLs line concerned is: path('user/detail/<uuid:pk>', UserDetailView.as_view(), name='userdetail'), the template referring to it is: <a href="{% url 'userdetail' user.pk %}"> which is generating the following URL: http://127.0.0.1:8000/accounts/user/detail/809b0ec2-d604-4171-8966-0817bfd59c88 however I get: Reverse for 'userdetail' with arguments '('',)' not found. 1 pattern(s) tried: ['accounts/user/detail/(?P[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$']. If I use the username e.g. email from AbstractBase User, the detail view doesn't like it as it wants Pk or slug. Help would be greatly appreciated. -
Crispy forms are not showing in the template browsing
i am trying to make a blog in django and on the github here is the code i am trying set the cripy form template in change password option and made some file names password_change_form.html, password_change_done.html etc. but when try to browse http://127.0.0.1:8000/accounts/password_change/done/ or any kind of pages related to password change section it is not showing the crispy form. but login or signup links are showing in crispy form. password change forms are showing in basic django form. i want to change it into the desired ones. i made two apps : blogapp and accounts. i am copying the urls below: blogapp/urls.py: from django.urls import path from .views import (BlogappListView, BlogappPostView, BlogappCreateview, BlogappUpdateView, BlogappDeleteView, ) urlpatterns = [ path('post/<int:pk>/delete/',BlogappDeleteView.as_view(),name='post_delete'), path('post/<int:pk>/edit/',BlogappUpdateView.as_view(),name='post_edit'), path('post/new/', BlogappCreateview.as_view(),name='post_new'), path('post/<int:pk>/',BlogappPostView.as_view(),name='post_detail'), path('',BlogappListView.as_view(),name='home'), ] accounts/urls.py: from django.urls import path from .views import SignUpView urlpatterns = [ path('signup/',SignUpView.as_view(),name='signup') ] blog_project/urls.py: from django.contrib import admin from django.urls import path,include from django.views.generic.base import TemplateView urlpatterns = [ path('admin/', admin.site.urls), path('accounts/',include('accounts.urls')), path('accounts/',include('django.contrib.auth.urls')), path ('',include('blogapp.urls')), path('',TemplateView.as_view(template_name='home.html'),name='home') ] i just can't figure out what am i missing and or what did i wrong? password change suppose to show the crispy form....not in django basic form. please let me know where is my mistake.thanx in … -
Do I need to use REST framework on Django?
Do I need to use the REST framework on Django, if I were to use a front-end framework such as React and database engine such as MongoDB or PostgreSQL? I also don't fully understand what a REST framework is. -
Django Rest Framework change serializer foreign key field's queryset based on user
Suppose I have these models: class Department(Model): ... class Building(Model): department = ForeignKey(Department, on_delete=CASCASE, related_name='buildings') staff = ManyToManyField(User) and I have 2 serializers for these models class DepartmentSerializer(ModelSerializer): class Meta: model = Department # how do I change this list of buildings accordingly to the user making the request? fields = (..., 'buildings') class BuildingSerializer(ModelSerializer): class Meta: model = Buiding fields = '__all__' What I want to do is, when a user requests for a Department, e.g. via a ViewSet, the result comes back is JSON data from the serializer, but the buildings field only contains the buildings that the user works in. So for example, user 'alice' and 'bob' both work in department 1. Department 1 consists of 5 buildings, [1, 2, 3, 4, 5]. However, alice only works in buildings 1 and 2, while bob works in buildings 3 and 4. And when alice requests to get department 1 data, she should get back { "id": 1, ... "buildings": [1, 2] } and if bob requests for department 1 as well, he should get back { "id": 1, ... "buildings": [3, 4] } Is there a way to do that using Django Rest Framework? I've thought about using … -
TemplateSyntaxError at on django and html
I am having an error "TemplateSyntaxError at /" i can not understand how to solve it.please help with this..thank you. en <!DOCTYPE html> {%load staticfils%} <html lang="en"> <head> <meta charset="UTF-8"> <title>home</title> <link rel="stylesheet" href="{%static'css/main.css'%}" /> </head> <body> <h1>Hello world</h1> </body> </html> -
Custom domain on linux server apache2 Django
I'm trying to set custom domain on my Django project, but still I have message err_CONNECTION_TIMED_OUT. Ip works fine. Apache2/project.conf <VirtualHost *:80> ServerName www.uczsieit.pl ServerAlias uczsieit.pl ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /static /home/adam/personal_blog_project/personal_blog/conf/static <Directory /home/adam/personal_blog_project/personal_blog/conf/static> Require all granted </Directory> Alias /media /home/adam/personal_blog_project/personal_blog/conf/media <Directory /home/adam/personal_blog_project/personal_blog/conf/media> Require all granted </Directory> <Directory /home/adam/personal_blog_project/personal_blog/conf> <Files wsgi.py> Require all granted </Files> </Directory> WSGIScriptAlias / /home/adam/personal_blog_project/personal_blog/conf/wsgi.py WSGIDaemonProcess django_app python-path=/home/adam/personal_blog_project/personal_blog python-home=/home/adam/$ WSGIProcessGroup django_app </VirtualHost> I added domain to Django Allowed hosts and set Reverse DNS and A/AAAA Records as well. In error.log of apache lack of info about errors. -
Pycharm no longer runs python scripts inside django project - not finding settings
I tried changing the root directory for the project (to match a productions servers structure so relative importing matches) and managed to screw up pycharm to the point that I can't even run scripts on new django projects. I imagine this has to do with how the venv is configured in pycharm, but have tinkered for hours changing relative import names and can not figure it out. I vaguely remember having to change the environment variables in the pycharm configs, but can't find anything like that when googling. Thank you in advance for any and all help. The error I receive is: C:\Users\steve\Documents\www\Scripts\python.exe C:/Users/steve.levy/Documents/www/mysite/main/test.py Traceback (most recent call last): File "C:/Users/steve/Documents/www/mysite/main/test.py", line 1, in <module> from mysite.main.models import ModelTest File "C:\Users\steve\Documents\www\mysite\main\models.py", line 5, in <module> class ModelTest(models.Model): File "C:\Users\steve\Documents\www\lib\site-packages\django\db\models\base.py", line 107, in __new__ app_config = apps.get_containing_app_config(module) File "C:\Users\steve\Documents\www\lib\site-packages\django\apps\registry.py", line 252, in get_containing_app_config self.check_apps_ready() File "C:\Users\steve\Documents\www\lib\site-packages\django\apps\registry.py", line 134, in check_apps_ready settings.INSTALLED_APPS File "C:\Users\steve\Documents\www\lib\site-packages\django\conf\__init__.py", line 76, in __getattr__ self._setup(name) File "C:\Users\steve\Documents\www\lib\site-packages\django\conf\__init__.py", line 61, in _setup % (desc, ENVIRONMENT_VARIABLE)) django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings. Process finished with exit code 1 manage.py: #!/usr/bin/env python """Django's command-line … -
Django and MongoDB on Centos 7
I'm trying to connect Django and MongoDB on a remote machine running Centos 7. I've made the following changes to the settings.py file DATABASES = { 'default': { 'ENGINE': 'djongo', 'NAME': 'database_name', 'HOST': '127.0.0.1', 'PORT': 27017, 'USER': 'mongodb_user_name', 'PASSWORD': 'mongo_db_password', } } Version numbers of packages used: Django 2.2.12 djongo 1.3.2 MongoDB 4.2.5 When I start the server using python3 manage.py runserver, I get the following message: Performing system checks... System check identified no issues (0 silenced). May 07, 2020 - 20:29:57 Django version 2.2.12, using settings 'djangoserver.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. However, when I connect to the remote machine using it's ip address http://XXX.XX.XX.XX:8000, I get an unable to connect message. Is the settings file set correctly? Any help will be appreciated. -
Django query omitting expected results
I must perform a query on a large database with a somewhat intricate modeling, which I will try to abridge below: class ScreeningItem(models.Model): # other fields receivedItem = models.OneToOneField(ReceivedItem, null=True, on_delete=models.SET_NULL) class ReceivedItem(models.Model): # other fields dossier = models.ForeignKey(Dossier, null=True, on_delete=models.SET_NULL) class Dossier(models.Model): # other fields subjects = models.ManyToManyField('SubjectTypes', through='Subjects', through_fields=('dossier', 'subjectType')) class Subject(models.Model): main = models.BooleanField(null=True) dossier = models.ForeignKey(Dossier, null=True, on_delete=models.SET_NULL) subjectType = models.ForeignKey(SubjectType, null=True, on_delete=models.SET_NULL) class SubjectType(models.Model): # other fields name = models.CharField(max_length=255, null=True, blank=True) parent = models.ForeignKey('self', null=True, on_delete=models.SET_NULL) Now, the problem is that I must find in ScreeningItem table items when the far, far away related field SubjectType.name contains specific words. No, worse. As you can see below, there's a parent-child self reference in that model, and I must look for those specific words in the related SujectType, its parent, and its grandparent, in case they exist. My attempt: exp = 'something' queryset = ScreeningItem.objects.filter( Q(receivedItem__dossier__subjects__subjecttype__name__iregex=exp) | Q(receivedItem__dossier__subjects__subjecttype__parent__name__iregex=exp) | Q(receivedItem__dossier__subjects__subjecttype__parent__parent__name__iregex=exp)) However, when I received a number of records much below I was expecting, I checked the database and discovered, for my astonishment, that there were many ScreeningItem which had a ReceivedItem which had a Dossier which was related to SubjectTypes which had the word I was … -
Errors deploying Django on Heroku
I have 2 problems Before I didn't upload my model to the DB (MariaDB) error load model Now it gives me an error in the configuration DB Before I used this configuration import dj_database_url from decouple import config DATABASES = { 'default': dj_database_url.config( default=config('JAWSDB_MARIA_URL') ) } Now the documentation shows another config Django but for both it shows me the same error enter load -
Django: How to graph/visualize the variable average in a scatter plot?
was wondering how do I visualize this data in a scatter plot way so it appears in the same Django template page below so that the average price is in the middle as a dot showing the price and the other prices in the list are other smaller dots scattered around it? Ford C-MAX 2011 1.6 Diesel 3950 May 7, 2020, 7:28 p.m. Ford C-MAX 2011 1.6 Diesel 5250 May 7, 2020, 7:28 p.m. Ford C-MAX 2011 1.6 Diesel 16950 May 7, 2020, 7:28 p.m. Ford C-MAX 2011 1.6 Diesel 3950 May 7, 2020, 7:32 p.m. Ford C-MAX 2011 1.6 Diesel 5250 May 7, 2020, 7:32 p.m. Ford C-MAX 2011 1.6 Diesel 5950 May 7, 2020, 7:32 p.m. Ford C-MAX 2011 1.6 Diesel 6750 May 7, 2020, 7:32 p.m. Ford C-MAX 2011 1.6 Diesel 8950 May 7, 2020, 7:32 p.m. {'price__avg': 7125.0} {'price__max': 16950} {'price__min': 3950} Note that these values are coming from a query form and results are being drawn from the database so for a different query (e.g. Ford Focus etc. ) these and price values would be different. Basically just looking for a way to visualize the results with emphasis on the average. -
Pass value from url request with Django generic detail view
From the GenericList, when clicking on one I redirect towards url(r'^machine/(?P<pk>[0-9]+)$', MachineDetailView.as_view(), name='machine-detail'), Where class MachineDetailView(DetailView): model = Awg template_name = 'gui/machine_detail.html' context_object_name = 'last_entry' ordering = ['-timestamp'] However what I need is to fetch AWG records where machine.id is foreign key in AWG's. In my mind it would look like that: class MachineDetailView(DetailView): last_entry = Awg.objects.filter(machine_id=Machine.objects.filter(id=pk).first()).first() model = Awg template_name = 'gui/machine_detail.html' context_object_name = 'last_entry' ordering = ['-timestamp'] That doesn't work because I don't know how to get that pk that is in the url requested. Apologies if noob, I did try to look in django docs. -
What does it mean by "For populating columns a and b, add the code in this model" in Django?
I have a requirement at work where the columns of a paginated table in the UI should be: Person ID First Name Last Name Person Status: Latest Status of Person Full Name Is Adult (Adult if person > 18 years of age) Profile Pic (Icon) if available Now, I have three models, namely: Person: Fields first_name, last_name, date_of_birth, gender, profile_pic (Nullable), created_at, modified_at PersonStatus: Fields person (FK Person), status_text, created_at, modified_at FormulaFields: formula(TextField that is able to store python code of up to 2000 characters), column_number (Integer >=4), created_at, modified_at I'm unclear what FormulaFields does, will need to clarify on Monday but want to finish it, or at least do something. For populating columns 5 and 6, I need to add the code in FormulaFields model. The column number of Formula Field should map with the Column number of above table (at the top, person ID to profile_pic). The above line confuses me, "For populating columns 5 and 6, add the code in FormulaFields model". To show the column full name and is adult, I need to add them as columns in the FormulaFields model, or do I add a method in FormulaField that will calculate them (but FormulaField doesn't …