Shivam
cj
Jame
What is the respective sql equivalent of the 2 django annotation filter below? Assuming 'Book' has Foreign key to 'Publisher'
Publisher.objects.annotate(num_books=Count('book',distinct=True)).filter(book_rating_gt=3.0)
Publisher.objects.filter(book_rating_gt=3.0).annotate(num_books=Count('book'))
Maxim
kiran
I want to execute a function everyday to change model value. Is there any way
Jame
test? quiz? exam?
https://docs.djangoproject.com/en/3.1/topics/db/aggregation/
It is from django document...I just curious how would it look like in sql equivalent
Jame
You can take it as quiz if you like the challenge 😁
Ali
When time we should start to use Django version 4.2
null
Charly
Ali
Okay thank you bro
Karthik
can any one tell me how to integrate swagger into my project ?
Денис
Kh
kiran
Okay let me try..
kiran
CRONJOBS = [
('*/2 * * * *', 'main.cron.my_cron_job')
]
kiran
def my_cron_job():
print( "iam running mann")
kiran
will this print data in terminal for evry 2 minutes
Airodragon
I am building a CRM using django, which frontend I should use that will be light and friendly.
Karthik
taofyboy
Raad
Hello
I'm having hard time to translate the choices in my model.
I have this one
ONLINE = "Online"
VISIT = "Direct "
RESERVATION_SOURCE_CHOICES = (
(ONLINE, ONLINE),
(VISIT, VISIT),
)
I'm using it in my code everywhere something like that
if res_source == ONLINE:
.....
Could you please help me guys ?
Raad
I did this but nothing happened.
ONLINE = _("Online")
VISIT = _("Direct")
RESERVATION_SOURCE_CHOICES = (
(ONLINE, ONLINE),
(VISIT, VISIT),
)
Ajay Kumar
Hello
I'm having hard time to translate the choices in my model.
I have this one
ONLINE = "Online"
VISIT = "Direct "
RESERVATION_SOURCE_CHOICES = (
(ONLINE, ONLINE),
(VISIT, VISIT),
)
I'm using it in my code everywhere something like that
if res_source == ONLINE:
.....
Could you please help me guys ?
Hello! It looks like you're using Python to define a RESERVATION_SOURCE_CHOICES tuple with two options: ONLINE and VISIT.
To clarify, ONLINE and VISIT are string constants that represent the values for the RESERVATION_SOURCE_CHOICES tuple.
When you use RESERVATION_SOURCE_CHOICES in your code, you can refer to ONLINE and VISIT to indicate the selected option.
For example, in your code, if res_source is equal to ONLINE, then the condition if res_source == ONLINE: will evaluate to True. Similarly, if res_source is equal to VISIT, the condition if res_source == VISIT: will evaluate to True.
I hope that helps! Let me know if you have any further questions or concerns.
Raad
Hello! It looks like you're using Python to define a RESERVATION_SOURCE_CHOICES tuple with two options: ONLINE and VISIT.
To clarify, ONLINE and VISIT are string constants that represent the values for the RESERVATION_SOURCE_CHOICES tuple.
When you use RESERVATION_SOURCE_CHOICES in your code, you can refer to ONLINE and VISIT to indicate the selected option.
For example, in your code, if res_source is equal to ONLINE, then the condition if res_source == ONLINE: will evaluate to True. Similarly, if res_source is equal to VISIT, the condition if res_source == VISIT: will evaluate to True.
I hope that helps! Let me know if you have any further questions or concerns.
Thanks for your answer.
my issue is the translation not appearing in my frontend. My concern was that if I use another method to translate such as this one
RESERVATION_SOURCE_CHOICES = (
('ONLINE', _('ONLINE')),
('VISIT', _('VISIT')),
I won't be able to use the evaluation method that you mentioned which will break my code because I have a large code which also require a lot of changes. Hope you got my point
Alexey
Alexey
Alexey
Raad
for what purpose?
Because the saved record appearing in English. If i create same record, the text get translated
Alexey
Alexey
Alexey
look at serializators. may be u make raw query and dont use translations
Amnas
I want to upload multiple image in in single post which is the best way to do that did i need to create a separate model like this
class Post(models.Model):
title = models.CharField(max_length=255)
description = models.TextField()
created_date = models.DateTimeField(auto_now_add=True)
def str(self):
return self.title
class Image(models.Model):
post = models.ForeignKey(Post, on_delete=models.CASCADE)
image = models.ImageField(upload_to='images/')
Alexey
how u will separate them? by ID? better make field name and save there filename
Lolilop
django not saving session key at database at production, what should I do to solve this problem? I did everything which mentioned at stackoverflow
EFK$$$
Hello here
Can anybody give me some examples of create a using wallet in each user please
Eg
User=models.Foreigenkey(User)
Blanace=models.IntegerFields(default=0)
I mean how can I put the models in views whenever new user register any help
Alexey
Alexey
Careful
Careful
thans for the article. I use signals 😅
Careful
OK. thanks
Careful
When to Use Django Signals · David Seddon
https://seddonym.me/2018/05/04/django-signals/
Juan
Hi, I'm trying to implement limit offset and pagination in api backend, but it's quite difficult for me ,
Can use of rest_framework limit offset and pagination can be used together?
Juan
This the settings
REST_FRAMEWORK = {
# "DEFAULT_PAGINATION_CLASS": "nocharges.pagination.MyPagination",
# "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
"PAGE_SIZE": 20,
"DEFAULT_PERMISSION_CLASSES": [
"rest_framework_api_key.permissions.HasAPIKey",
],
"DEFAULT_AUTHENTICATION_CLASSES": [
"config.authentication.JWTAuthentication",
"rest_framework.authentication.SessionAuthentication",
],
'DATETIME_FORMAT': "%Y-%m-%d %H:%M:%S",
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination'
}
Juan
and ModelViewSet
class NochargeViewSet(ModelViewSet):
queryset = Nocharge.objects.all().order_by('-created')
serializer_class = NochargeSerializer
filter_backends = [DjangoFilterBackend, SearchFilter]
filterset_fields = ['domain', 'category_free']
search_fields = ['title', 'overview']
Juan
#need_help
Александр
Hello. Has anyone encountered a problem why images are not displayed on the page in django?
Ali
Your static url can be wrong
Александр
in settings?
Ali
Yes send your setting codes html codes
Nitin
Александр
added everything as it should, tried everything, any ideas?
Ali
Bro give access your media url and root in your root url
Ali
import this ones
from django.conf.url.static import static
from django.conf import setting
Ali
Then add this code end of your url patterns ....] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Ali
It will fix the error
Александр
https://linkode.org/#KHLnJPfkHSbqeHWgjzUOb2
Fil
vahiden
Hey guys i want create bookly website i learn python css html and django is enough or should learn javascript ?
Aman Deoli
I want help in writing drf serializer for the manytomany field
YAVIS
vahiden
YAVIS
Thanks lot
You're welcome. I wish your success.
Aman Deoli
Where should I share code so that you all can help with it