Any way to avoid querying for request.user on every request?

2020-07-14 Thread Asaduzzaman Sohel
When any user login my Django web application, I want to user_id, user_group, user_type in session. Because I wanna avoid querying request.user on every request for web page faster. So, I saved this and I would like to pass this parameter User.objects.get(pk=request.session.get( 'user_id')) But

How can I filter django many to many models?

2020-09-21 Thread Asaduzzaman Sohel
class User(PermissionsMixin, AbstractBaseUser): name = models.CharField(max_length=511, null=True, blank=True) email = models.EmailField(unique=True) phone_number = PossiblePhoneNumberField(blank=True, null=True, default=None) addresses = models.ManyToManyField(Address, blank=True) is_staff = mode

Dynamic Logo

2020-10-18 Thread Asaduzzaman Sohel
I am creating a django application. now I would like to create logo, site name & info which will be dynamic. I want to create Model for this , but problem is use create many logo, site name or info. but Use can create or edit only one logo, one site name. How can I do this? -- You received thi

How add raw query in a Model

2021-02-28 Thread Asaduzzaman Sohel
this is query: ``` sub_query = PaymentDetails.objects.filter(order=OuterRef('pk')).order_by('-updated_at')[:1] payment_summary = """select jsonb_build_object( 'total_paid_amount', coalesce(sum(amount), 0), 'total_due_amount', CASE WHEN (order_order.total_gross - coalesce(sum(amount), 0)) > 0.02 t

Django 3.2 AttributeError: 'TextField' object has no attribute 'db_collation'

2021-04-07 Thread Asaduzzaman Sohel
I've an existing project on Django 3.1 and I upgraded my project to Django 3.2. I created an app called payment on my project. But When I make migrations. It trow an error ```AttributeError: 'TextField' object has no attribute 'db_collation'``` ``` from django.db import models from django.conf i

Doesn't save data django Foreignkey model

2019-08-25 Thread Asaduzzaman Sohel
I've two model. I would like to save data from ForeignKey model. I'm created a modelform and save with my main foreignkey model. But I got this error ValueError at /c/customer/1/ Cannot assign "'1'": "BillingData.customer" must be a "CustomerData" instance. I created Django model form and ho