Django community: RSS
This page, updated regularly, aggregates Django Q&A from the Django community.
-
Making Stripe User Checkout Email as {{ request.user.email }} in Django project
Hi Djangonauts, I am integrating stripe in my in my project. I have the below form. When this form renders. It asks for users. Name:, Email:, Billing Address:, Credit Card Details:, Can I change email from email = request.POST['stripeEmail'] to If user.is_authenticated: email = request.user.email I am aware that by doing this anonymous users will not be able to checkout and I am ok with that. Below are the views.py of my shopping cart def cart_detail(request, total=0, counter=0, cart_items=None): try: cart = Cart.objects.get(cart_id=_cart_id(request)) cart_items = CartItem.objects.filter(cart=cart, active=True) for cart_item in cart_items: total += (cart_item.tasting.price * cart_item.quantity) counter += cart_item.quantity except ObjectDoesNotExist: pass stripe.api_key = settings.STRIPE_SECRET_KEY stripe_total = int(total * 100) description = 'Khal: Share your recipes - New tasting request' data_key = settings.STRIPE_PUBLISHABLE_KEY if request.method == 'POST': # print(request.POST) try: token = request.POST['stripeToken'] email = request.POST['stripeEmail'] billingName = request.POST['stripeBillingName'] billingAddress1 = request.POST['stripeBillingAddressLine1'] billingCity = request.POST['stripeBillingAddressCity'] billingZipcode = request.POST['stripeBillingAddressZip'] billingCountry = request.POST['stripeBillingAddressCountryCode'] customer = stripe.Customer.create( email=email, source=token ) charge = stripe.Charge.create( amount=stripe_total, currency='usd', description=description, customer=customer.id, ) '''Creating the Order''' try: order_details = Order.objects.create( token=token, total=total, emailAddress=email, billingName=billingName, billingAddress1=billingAddress1, billingCity=billingCity, billingZipcode=billingZipcode, billingCountry=billingCountry, ) order_details.save() for order_item in cart_items: oi = OrderItem.objects.create( tasting=order_item.tasting.post.title, quantity=order_item.quantity, price=order_item.tasting.price, order=order_details ) oi.save() '''Reduce stock when Order is … -
Pass settings argument to collectstatic when called inside the code
BaseCommand doesn't have a dest keyword for --settings argument. Thus I am unable to figure out how to pass settings file to collectstatic when called programmatically, like: from django.core import management # ... # management.call_command('collectstatic', interactive=False) Any ideas? -
Django not REST - API user registration
I have my first project as junior in my work. It is old (Django 1.8) and it is normal django framework... not REST. It supports web, and mobile. I have to create endpoint for mobile to create user. I think it is not a problem (to create) but I want to make sure it will be save. First of all I thought that I will create normal ModelForm (RegisterAPIForm based on model=User with full validation (I mean init all fields that are in "backend" not visible for user | cleaned_data for all fields | special overwriten method save() that in addition hashes password, and send email) and in Views I'll add something like this: class RegistrationAPITestView(View): def post(self, request): form = RegistrationAPIForm( request.POST ) if form.is_valid(): form.save() return JsonResponse({}) else: #check errors and send error code back Or I should do it other way, by using User object? class RegistrationAPITestView(View): def post(self, request): #check if user does not exist #password1 and password2 validation user = User.objects.create() user.name = request.POST['username'] user.set_password(request.POST['password']) #init all fields that user can't choose like groups etc user.save() What do you think? Do I need ModelForm that I won't even render? It seems to be safer, but … -
Django 2, Python 3: Extending user model with different profile types
I'm trying to have users, which will either be doctors or patients(for now, as I'm planning to add more user types). In the app called user, I've User model, which extends AbstractUser. In app patients, I have model for Patient user profile, and the same for doctors app, Doctor model. Both Patient and Doctor models are regular Django models. Then, I have created Patient registration form, and I'm trying to register a single patient. When I do, I get the following error: 'Patient' object has no attribute 'set_password'. My models: class User(AbstractUser): USER_TYPE_CHOICES = ( ('patient', 'Patient'), ('doctor', 'Doctor') ) user_type = models.CharField( max_length=20, choices=USER_TYPE_CHOICES, default='patient', ) username = models.CharField(max_length=100, blank=True, null=True) email = models.EmailField('email address', unique=True) objects = DoktorinoUserManager() USERNAME_FIELD = 'email' REQUIRED_FIELDS = [] def __str__(self): return self.email class Patient(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='main_user') first_name = models.CharField(max_length=30, blank=False) last_name = models.CharField(max_length=30, blank=False) USERNAME_FIELD = 'email' phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Phone number must be in the following format: '+999999999'.") phone_number = models.CharField(validators=[phone_regex], max_length=17, blank=True) address = models.CharField(max_length=300, blank=False) city = models.ForeignKey(City, on_delete=models.CASCADE) def __str__(self): return self.first_name + ' ' + self.last_name My forms.py: class PatientSignUpForm(UserCreationForm): first_name = forms.CharField(max_length=50, required=True) last_name = forms.CharField(max_length=50, required=True) email = forms.EmailField(required=True) phone_number = forms.RegexField( … -
Why won't pip let me install django?
Pip will not let me install django 2.0.7. When I execute sudo -H pip install Django==2.0.7 it says: "Could not find a version that satisfies the requirement Django==2.0.7 (from versions: 1.1.3, 1.1.4, 1.2, 1.2.1, 1.2.2, 1.2.3, 1.2.4, 1.2.5, 1.2.6, 1.2.7, 1.3, 1.3.1, 1.3.2, 1.3.3, 1.3.4, 1.3.5, 1.3.6, 1.3.7, 1.4, 1.4.1, 1.4.2, 1.4.3, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.4.8, 1.4.9, 1.4.10, 1.4.11, 1.4.12, 1.4.13, 1.4.14, 1.4.15, 1.4.16, 1.4.17, 1.4.18, 1.4.19, 1.4.20, 1.4.21, 1.4.22, 1.5, 1.5.1, 1.5.2, 1.5.3, 1.5.4, 1.5.5, 1.5.6, 1.5.7, 1.5.8, 1.5.9, 1.5.10, 1.5.11, 1.5.12, 1.6, 1.6.1, 1.6.2, 1.6.3, 1.6.4, 1.6.5, 1.6.6, 1.6.7, 1.6.8, 1.6.9, 1.6.10, 1.6.11, 1.7, 1.7.1, 1.7.2, 1.7.3, 1.7.4, 1.7.5, 1.7.6, 1.7.7, 1.7.8, 1.7.9, 1.7.10, 1.7.11, 1.8a1, 1.8b1, 1.8b2, 1.8rc1, 1.8, 1.8.1, 1.8.2, 1.8.3, 1.8.4, 1.8.5, 1.8.6, 1.8.7, 1.8.8, 1.8.9, 1.8.10, 1.8.11, 1.8.12, 1.8.13, 1.8.14, 1.8.15, 1.8.16, 1.8.17, 1.8.18, 1.8.19, 1.9a1, 1.9b1, 1.9rc1, 1.9rc2, 1.9, 1.9.1, 1.9.2, 1.9.3, 1.9.4, 1.9.5, 1.9.6, 1.9.7, 1.9.8, 1.9.9, 1.9.10, 1.9.11, 1.9.12, 1.9.13, 1.10a1, 1.10b1, 1.10rc1, 1.10, 1.10.1, 1.10.2, 1.10.3, 1.10.4, 1.10.5, 1.10.6, 1.10.7, 1.10.8, 1.11a1, 1.11b1, 1.11rc1, 1.11, 1.11.1, 1.11.2, 1.11.3, 1.11.4, 1.11.5, 1.11.6, 1.11.7, 1.11.8, 1.11.9, 1.11.10, 1.11.11, 1.11.12, 1.11.13, 1.11.14) No matching distribution found for Django==2.0.7" As you can see above, the most recent version it can find is version … -
django-rest-framework - POST Request returns "Method \"GET\" not allowed."
I have set up django-rest-auth as per the installation tutorial, yet I am not able to use the login API endpoint. When I send a POST request with the correct information, I receive a 405 status error in response with "Method "GET" not allowed." However, when I navigate to the actual URL and POST it from the online form, it works fine and returns a token. Help?! -
How to access many to many model field in django
I have a model class Employee(models.Model): coverage = models.ManyToManyField('Coverage') And another model class Coverage(models.Model): time_needed = models.IntegerField() I need to display time needed for each employee but it list all of them this is what I have tried {% for employee in employee %} {% for coverage in employee.coverage.all %} {{ coverage.time_needed }} min {% endfor %} {% endfor %} But it iterates through each item. I basically need a way of accesing and displaying the time needed for each employee Any helpful answer would be appreciated thanks ps: This is a part of a larger model class -
Does Django Rest Framework have third party apps to auto generate swagger.yaml file?
I have large amount of API endpoints written in django-rest-framework and it keeps increasing and updating. How can I create & maintain API documentation that should be up-to-date? My current version is Create swagger.yaml file and somehow auto generate everytime any endpoint changes. Then use this file as an input to readme.io, ReDoc or other alternatives to provide visualization to external folks. If you have an experience on this or any similar solution, please share I really appreciate it! -
Django Count filter with models.Q on related field
Why does this filter not work. I'm on Django 2.0 and as far as I know this is supported from the other answers here and on the documentation. Let's say my models are: class ModelA(models.Model): # fields class ModelB(models.Model): item = models.ForeignKey(ModelA, related_name='votes') active = models.BooleanField(default=True) My filter is: .annotate(models.Count('votes', filter=models.Q(votes__active=False)) So, I want to count only the relations with active = False. -
How and where can I sort an array of Django <django.utils.functional.lazy> objects?
I have a list of tuples with countries/cities combinations from which I populate a select field in django. I'm loading placeholders for the select options using a configparser in my settings.py: scope_value_list = dict(raw_parser.items('scope_value_list')) CATEGORIES = SimpleNamespace(**{ "SCOPE_CHOICES": [(code_tuple[1], _(scope_value_list[code_tuple[0]].partition('{% trans "')[2].partition('" %}')[0])) for code_tuple in raw_parser.items('scope_list')], ... }) A bit cumbersome but I cannot provide hardcoded translations outside of the django.po/mo files and haven't found a better solution than to include my .ini file in my makemessages calls and then strip the translation flags as shown above to build my list of choices. However this means my SCOPE_CHOICES contains lazy-translated-objects and not actual translations, so I have: [('eu', <django.utils.functional.lazy.<locals>.__proxy__ object at 0x7ff11f7ad470>), ('eu-at', <django.utils.functional.lazy.<locals>.__proxy__ object at 0x7ff11f7adba8>), ('eu-be', <django.utils.functional.lazy.<locals>.__proxy__ object at 0x7ff11f7adc50>), ('eu-bg', <django.utils.functional.lazy.<locals>.__proxy__ object at 0x7ff11f7adcc0>), ('eu-hr', <django.utils.functional.lazy.<locals>.__proxy__ object at 0x7ff11f7b6278>),...] This all works (yay), but when I display the select field in any template it will go by the order in the tuple (array would be the same), so countries are not sorted A-Z by their actual name and I can't figure out how to do it in a language-agnostic way. I understand that lazy-translation will be run when "when it is needed" so the only place, … -
I can return empty values in an annotate - django?
I want to get all the amounts and the amount per state per week: class DashboarAPIView(APIView): def post(self, request): data = request.data date = data.get('date', None) date = data.get('date', None) current_date = datetime.datetime.strptime(date, '%Y-%m-%d') start_week = current_date - datetime.timedelta(current_date.weekday()) end_week = start_week + datetime.timedelta(6) indicatorMount = DispatchAction.objects.filter(date_start__date__range=(start_week, end_week))\ .annotate(fecha=TruncDate('date_start'))\ .values('status_id', 'status__name', 'fecha')\ .annotate(amount=Sum('route_dispatch__dispatch__amount'), count=Count('status')) result['indicatorMount'] = indicatorMount return Response(result, status=status.HTTP_200_OK) This works correctly but when there is no data it simply does not return anything to me and I would like to know if there is a possibility that when there is no data for that date, I will paint them but with their empty values? -
Django: how to solve "Apps aren't loaded yet" error on model import?
In my app's "views.py" file I have the following import: from .models import City The import and the app work fine when launched on localhost. In the same folder as "views.py" and "models.py" I have created another file "database_import.py" for making a one-time database import from .csv file. If I would use the same line as above to import City model into "database_import.py" file, I would get an error: Traceback (most recent call last): File "database_csv_imports.py", line 3, in <module> from .models import City SystemError: Parent module '' not loaded, cannot perform relative import So I have changed relative import to absolute: from models import City This, however, throws another error: Traceback (most recent call last): File "database_csv_imports.py", line 3, in <module> from models import City File "/home/bart/python_projects/javascript/models.py", line 19, in <module> class Listing(models.Model): File "/home/bart/python_projects/testenv/lib/python3.5/site-packages/django/db/models/base.py", line 100, in __new__ app_config = apps.get_containing_app_config(module) File "/home/bart/python_projects/testenv/lib/python3.5/site-packages/django/apps/registry.py", line 244, in get_containing_app_config self.check_apps_ready() File "/home/bart/python_projects/testenv/lib/python3.5/site-packages/django/apps/registry.py", line 127, in check_apps_ready raise AppRegistryNotReady("Apps aren't loaded yet.") django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. I have looked at similar SO questions, but haven't found a solution: I am running all scripts inside virtualenv, my app is installed in "settings.py", SECRET_KEY is not empty, and both makemigrations and migrate … -
How to add custom text field to the django mezzanine blog post?
I want to add a custom text field to the blog post. However, official documentation is not enough. I Added my project's settings.py this lines; EXTRA_MODEL_FIELDS = ( ( "mezzanine.blog.models.BlogPost.caption", "django.db.models.CharField", ("Media",), {"default": 'URL', 'max_length': 128}, ), ) according to the official document I need to add the following lines to some places; MIGRATION_MODULES = { "pages": "path.to.migration.storage.pages_migration", "forms": "path.to.migration.storage.forms_migration", "galleries": "path.to.migration.storage.galleries_migration", } but I do not know where to add it, I guess it could be the same setting.py file. but I do not know how to edit for my configuration. To create the new migration files and apply the changes, simply run: $ python manage.py makemigrations $ python manage.py migrate and finaly Admin Field; # In myapp/admin.py from copy import deepcopy from django.contrib import admin from mezzanine.blog.admin import BlogPostAdmin from mezzanine.blog.models import BlogPost blog_fieldsets = deepcopy(BlogPostAdmin.fieldsets) blog_fieldsets[0][1]["fields"].insert(-2, "image") class MyBlogPostAdmin(BlogPostAdmin): fieldsets = blog_fieldsets admin.site.unregister(BlogPost) admin.site.register(BlogPost, MyBlogPostAdmin) but which admin.py file. I need to create a folder admin.py file where the settings.py file is located? Official Documantation for Mezzanine 4.3.0 -
AttributeError 'DatabaseWrapper' object has no attribute 'set_schema_to_public'
I am trying to run my Django app via Docker on Heroku, but I am coming across this error when I try to load the page: tenant_schemas/middleware.py in process_request at line 46: AttributeError 'DatabaseWrapper' object has no attribute 'set_schema_to_public' The code errors on: from django.db import connection connection.set_schema_to_public() I'm on Django 2.0.7, and this code runs fine when I run it on the Heroku console. Also, my public schema and tenants are setup correctly in the database. I can't figure out what else I can check or fix? -
How to insert data into CreateAPIVIew's response
I currently have the following code which, upon creating an object, returns the serialization of the item. Class Item(Model): name = models.CharField(max_length=20, null=False) uid = models.CharField(max_length=40, null=False, default=uuid1) puid = models.CharField(max_length=40, null=True) class ServerCreateView(CreateAPIView): def perform_create(self, serializer): # Create instance = serializer.save() # Updates its previous uid puid = self.model_class.objects.values_list('uid', flat=True).filter(pk__lt=instance.pk).order_by('-pk')[:1][0] self.model_class.objects.filter(pk=instance.pk).update(puid=puid, sdtc=datetime.now()) I need to be able to return its puid though and it isn't calculated until after the model is saved. I know I can opt to go instance = serializer.save(puid={puid}) which will include its puid in the reponse however this leaves room for a race condition in the event that another Item is saved in between the time the puid is retrieved and the item itself is saved and I also need to prevent that. Is there any way to do this without opening my data up to risk? -
Retrieve all values from join?
I have 3 tables. User, Post, and Share. Post is a table that contains all posts. Post has a one to many relationship with Share. That being said, the Share table is a table where it indicates which posts a user has shared. Here's the structure of the tables: class Post(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) status = models.CharField(max_length=200) share_count = models.IntegerField(default=0) created_at = models.DateTimeField(auto_now_add=True) url = models.CharField(max_length=150) class Share(models.Model): post = models.ForeignKey(Post, on_delete=models.CASCADE) user = models.ForeignKey(User, on_delete=models.CASCADE) shared_at = models.DateTimeField(auto_now_add=True) Let's say we have a User with id 1. What I want to do is to show all posts + shares of that user ordered by date. Just like how Twitter does when you go to a User's Twitter profile. It shows all their Tweets + their Retweets ordered by date and time. What I've tried doing is this query: Share.objects.all().select_related('post').get(user=1) If I do this, I get an error that there is more than one share for this user. What am I doing wrong? The error: Example.models.MultipleObjectsReturned: get() returned more than one Share -- it returned 2! -
Django sum a column and also group by these column based on foreign key value
I need to sum unit from orderitem table and also calculate the sum of unit for a specific product_category_id OrderItem table Product Category Table My try is product_category_wise_sale = OrderItem.objects\ .annotate(total=Sum('unit')) \ .prefetch_related('product__product_category')\ .values('product_category_id', 'product_category__category_name') \ .annotate(product_category_wise_total_unit=Sum('unit')) It will return <QuerySet [{'product_category_id': 1, 'product_category__category_name': 'Mobile Phone', 'product_category_wise_total_unit': 7.0}, {'product_category_id': 3, 'product_category__category_name': 'T-Shirt', 'product_category_wise_total_unit': 7.0}]> I just also need total unit from order table. See the resultant queryset it will show product_category_id wise product_category_wise_total_unit 7 and 7. I also need the sum of product_category_wise_total_unit. I also need from orderitem table sum of the unit column is 14. How to resolve this? -
"page"/create is colliding because slug django
I wanna ask Question. In my Little Django Project. Im making Blog app, the create blog page is "blog/create/" and the detail of blog is "blog/{slug}". The slug is successfully Show in My page but the create page is not. Because maybe "create" is read as a slug by django. The point is , how to filter the "blog/create/" and "blog/{slug}/" this is my urls.py urlpatterns = [ path('', views.index, name="index"), path('<slug>/',views.show,name="show"), path('create/',views.create, name="create"), ] -
Anaconda/conda create environment with django 1.11 with cli command
I'm trying to create a new environment using conda with django package 1.11.13. Using conda create --name myEnv django is offering a django v2x, how can I specify the package version? -
Django 2, Python 3.5.2 - custom user model
I'm trying to create custom user model, with different user types, ie, patients and doctors. This being said, I've following apps in my django project: user, doctors, patients, cities and states. Now, when I try to python manage.py createsuperuser, wizard prompts for email and password, not asking for username. After I enter my email and password, this is the traceback: Traceback (most recent call last): File "manage.py", line 15, in <module> execute_from_command_line(sys.argv) File "/home/milos/.local/lib/python3.5/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line utility.execute() File "/home/milos/.local/lib/python3.5/site-packages/django/core/management/__init__.py", line 365, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/home/milos/.local/lib/python3.5/site-packages/django/core/management/base.py", line 288, in run_from_argv self.execute(*args, **cmd_options) File "/home/milos/.local/lib/python3.5/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 59, in execute return super().execute(*args, **options) File "/home/milos/.local/lib/python3.5/site-packages/django/core/management/base.py", line 335, in execute output = self.handle(*args, **options) File "/home/milos/.local/lib/python3.5/site-packages/django/contrib/auth/management/commands/createsuperuser.py", line 179, in handle self.UserModel._default_manager.db_manager(database).create_superuser(**user_data) TypeError: create_superuser() missing 1 required positional argument: 'username' Now, here's the relevant code from user.models(app user, models.py file): class User(AbstractUser): USER_TYPE_CHOICES = ( ('patient', 'Patient'), ('doctor', 'Doctor') ) user_type = models.CharField( max_length=20, choices=USER_TYPE_CHOICES, default='patient', ) username = models.CharField(max_length=100, blank=True, null=True) email = models.EmailField('email address', unique=True) USERNAME_FIELD = 'email' REQUIRED_FIELDS = [] and my patients.Patient model: class Patient(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) first_name = models.CharField(max_length=30, blank=False) last_name = models.CharField(max_length=30, blank=False) USERNAME_FIELD = 'email' phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Phone number must be in … -
How to call a model function from template?
I am calling my models(Answer) function isupvoted from template while iterating over all answers that are being shown on page to see if the loggedin user has liked the iterating answer. My Answer and Upvote models are as below. class Answer(models.Model): answer_text = models.TextField(max_length=5000) answer_author = models.ForeignKey(User, on_delete=models.CASCADE, related_name='ans_auth') question = models.ForeignKey(Question, on_delete=models.CASCADE) a_pub_date = models.DateTimeField('Date Answer Published') a_modified_date = models.DateTimeField('Date Answer Modified', null=True, blank=True) def __str__(self): return self.answer_text def isupvoted(self, request): counter = UpvoteAnswerMod.objects.filter(answer=self, upvote_user=request.user).count() print("upvote count: "+counter) return counter class UpvoteAnswerMod(models.Model): answer = models.ForeignKey(Answer, on_delete=models.CASCADE) upvote_user = models.ForeignKey(User, on_delete=models.CASCADE) upvote_date = models.DateTimeField('Date Upvoted') I am calling the function as below {% if answer.isupvoted == 1 %} <a class="upvote pressed" href="#" >Downvote</a> {% else %} <a class="upvote" href="#" >Upvote</a> {% endif %} But answer.isupvoted is not returning anything. How do I get the upvote count? -
what's feeding the 'user' in a django template
So I just learn about Class Based View, and how they pass a context to an according template for rendering. But I notice something weird in some code I attach below: the django template can recognize the user in if user.is_authenticated, but I check the context of Sdetailview, user is not in it. And when I log in as admin, the template will render 1, otherwise render 2. Does anyone know from where the user was passed to the template? what else is passed to template from class based view besides context? Thank you. here's the view: from django.views.generic import DetailView from . import models class Sdetailview(DetailView): context_object_name = "details" model = models.School template_name = "basicapp/sdetail.html" here's the model template {% extends "basicapp/bbase.html" %} {% block body_block %} {% if user.is_authenticated %} <h1>1</h1> {% else %} <h1>2</h1> {% endif %} <div class="container"> <h1>School Details</h1> <p>{{details.name}}</p> <p>{{details.principal}}</p> <p>{{details.location}}</p> <p><a class='btn btn-warning' href="{% url 'bapp:update' pk=details.pk %}">Update</a></p> </div> </div> {% endblock %} -
Can't log in super user created in django backend
I have the following methods to create user and super user in djagno. class UserManager(BaseUserManager): def create_user(self, email, username, password=None, is_staff=False, is_superuser=False, is_active=False, is_bot=False, is_mobile_verified=False, is_online=True, is_logged_in=True): if not email: raise ValueError('Email is required') if not username: raise ValueError('Username is required.') email = self.normalize_email(email) user = self.model(email=email, username=username, is_staff=is_staff, is_superuser=is_superuser, is_active=is_active, is_bot=is_bot, is_mobile_verified=is_mobile_verified, is_online=is_online, is_logged_in=is_logged_in) user.set_password(password) user.save(using=self._db) return user def create_superuser(self, email, username, password): return self.create_user(email, username, password=password, is_staff=True, is_superuser=True, is_active=True, is_bot=False, is_mobile_verified=False, is_online=True, is_logged_in=True) For some reason when I create a super user on the back end I cant log in using the same email and password. This is the post method on the logs POST /admin/bouncer/user/add/ HTTP/1.1" 302 0 How can i check if my create_super_user method was called? -
Would vuex state management be useful in implementing a multi page app with django?
I have created a single page app before with Vue and Vuex for state management and am looking into multi page apps with the django backend framework. I am curious to know if there would be any pros to including vuex state management or would the backend take care of state management in this case? -
Cannot access to_attr attribute in annotate()
I have the following code: queue = Queue_item.objects.prefetch_related(Prefetch('queue_item_id', queryset=Platform.objects.all().order_by('-time'), to_attr='platforms')) queue = queue.annotate(first_time=Min('platforms__time')).order_by('first_time') When I run it, I get an error message that says that in the queue.annotate, it cannot find platforms, even though I set it right before in the prefetch_related. What am I missing? Thanks!