Princode
Princode
Leonardo
Hi everyone! How to update images Gallery using Django?
I'm trying with list, form and instance; but I'm not getting it. Are there any examples for me to improve my implementation?
.
I need help to create help desk project
Charly
.
Okay, I want to create agent predefined credential using Create custom command for agent dashboard. I have created user registration page which redirect to user dashboard but now I want connect agent dashboard using predefined credential
Charly
Da
i think you can use pipeline for the above
.
Where name and password is given
Ajeet
Ajeet
.
It's big file
.
there are two apps one is the user dashboard and 2nd is the agent dashboard. to access user dashboard you can use registration and login, but i want to create agent user name password using Django custom command s
Charly
Leonardo
.
how we can differentiate login system between agent and user
Charly
Charly
but depending on the role you can show or not sections
Arturo
.
but the agent dashboard has a different one where they can see the user raises a ticket
Leonardo
Charly
.
superuser redirect to Django inbuilt dashboard
.
that i dont want
Charly
then change it
Leonardo
Charly
you are complicating yourself a lot for something that is very common
Charly
hacing diferent logins and users is just a lot of more work
.
then registration page would be different
Charly
.
but we can also use custom Management commands
Leonardo
.
instead of registration page
Leonardo
You inserte the user type of the form explicit or implicit...
Leonardo
insert*
.
we can use many way ...but my question is , can we can use the above method, if yes ...then how
.
i am trying whole day but not able to create
.
https://docs.djangoproject.com/en/5.0/topics/auth/customizing/
.
what if i want to predefine admin name and password in my code section but i dont want to use superuser
.
i dont want to predefine in setting file
.
.any way if anyone know please let me know
t
I am currently developing a Django app that involves individuals with their birth dates.
The birth dates are stored in Gregorian format in Django.
I use django-jalali-date to convert them to the Jalali calendar.
Currently, I need to create a task or a view to list all individuals born today (for example, the 28th of Khordad, regardless of the year) or send them a message. However, the main concern is just listing the exact birth date including month and day.
The challenge arises because of leap years and non-leap years, which makes filtering difficult due to a one-day discrepancy.
Here is my sample code where I need to filter both leap and non-leap years simultaneously, or if I filter for non-leap years, it shows different dates:
# birth_year not set in filters
def people_by_month_day(request, month_slug, day_slug):
jalali_month_fa = ['فروردین', 'اردیبهشت', 'خرداد', 'تیر', 'مرداد', 'شهریور', 'مهر', 'آبان', 'آذر', 'دی', 'بهمن', 'اسفند']
if month_slug.strip() in jalali_month_fa:
month = jalali_month_fa.index(month_slug.strip()) + 1
day = int(day_slug)
# Generate Gregorian dates for a normal year and a leap year
normal_gregorian_year = jdatetime.date(1403, month, day).togregorian()
leap_gregorian_year = jdatetime.date(1404, month, day).togregorian()
# Find people with birth dates matching either normal or leap year converted dates
people = Person.active.filter(
Q(birth_date__month=normal_gregorian_year.month, birth_date__day=normal_gregorian_year.day) |
Q(birth_date__month=leap_gregorian_year.month, birth_date__day=leap_gregorian_year.day)
)[:20]
context = {
'people': people,
'month': month,
'day': day,
'month_name': month_slug
}
return render(request, "person/people_by_month_day.html", context)
else:
return HttpResponseNotFound('<h1>Page not found</h1>')
In this code, I either filter both years, such as for leap and non-leap years:
people = Person.active.filter(
Q(birth_date__month=normal_gregorian_year.month, birth_date__day=normal_gregorian_year.day) |
Q(birth_date__month=leap_gregorian_year.month, birth_date__day=leap_gregorian_year.day)
)[:20]
Or I have to choose one:
If I filter for non-leap years:
people = Person.active.filter(
Q(birth_date__month=normal_gregorian_year.month, birth_date__day=normal_gregorian_year.day)
)[:20]
It correctly filters only individuals born in non-leap years by month and day.
If I filter for leap years:
people = Person.active.filter(
Q(birth_date__month=leap_gregorian_year.month, birth_date__day=leap_gregorian_year.day)
)[:20]
It correctly filters only individuals born in leap years and not those born in non-leap years.
For example:
26 Khordad 1370
1371
...
1380
1399
1402
and so on...
This causes a one-day discrepancy in their exact birth date likely due to leap years.
For instance, June 18th in two different years will differ if one is a leap year and the other is not:
18 - 6 - 1981
28 / 3 / 1360
18 - 6 - 2004
29 / 3 / 1383
What comes to mind is to create a temporary column in the Django filter called is_leap_year:
birth_date | is_leap_year
2004/4/5 | true
2005/6/4 | false
If it's a leap year, account for that extra day; otherwise, consider it a non-leap year. However, this query seems complex and may require using Where, Case, and annotation in Django.
If there is a better method, please let me know.
Suryo Adhy Chandra
{% extends 'users/base.html' %}
Login
{% block content %}
<form method="post">
<h1>SignIn</h1>
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Submit</button>
if you don't have account yet: <a href="{% url 'register' %}">SignUp</a>
</form>
{% endblock %}
Forbidden (403)
CSRF verification failed. Request aborted.
Help
Reason given for failure:
CSRF token from POST incorrect.
In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django’s CSRF mechanism has not been used correctly. For POST forms, you need to ensure:
Your browser is accepting cookies.
The view function passes a request to the template’s render method.
In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL.
If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data.
The form has a valid CSRF token. After logging in in another browser tab or hitting the back button after a login, you may need to reload the page with the form, because the token is rotated after a login.
You’re seeing the help section of this page because you have DEBUG = True in your Django settings file. Change that to False, and only the initial error message will be displayed.
You can customize this page using the CSRF_FAILURE_VIEW setting.
i don’t understand, why it doesn’t work
it seem you reload the page that contain POST method?
Nani
ValueError: Cannot assign &amp;amp;amp;amp;amp;amp;amp;quot;&amp;amp;amp;amp;amp;amp;amp;lt;django.contrib.auth.models.AnonymousUser object at 0x000001EA2C406310&amp;amp;amp;amp;amp;amp;amp;gt;&amp;amp;amp;amp;amp;amp;amp;quot;: &amp;amp;amp;amp;amp;amp;amp;quot;Comment.author&amp;amp;amp;amp;amp;amp;amp;quot; must be a &amp;amp;amp;amp;amp;amp;amp;quot;UserProfile&amp;amp;amp;amp;amp;amp;amp;quot; instance. i tried so many ways but i didnt get it.
Bayram
Bayram
Hassaan
DV
How to fetch user input data from database using filter method?
DV
Pls help!!! 🙏🏻
Suryo Adhy Chandra
DV
see django doc, it simply explained
But i haven&amp;amp;amp;amp;amp;amp;amp;#39;t seen about how to get specific data record using a single attribute value from database
Suryo Adhy Chandra
DV
Suryo Adhy Chandra
Ys
https://docs.djangoproject.com/en/5.0/ref/models/querysets/#pickling-querysets
Ex097
Hi All
How are you?
I am new on Django, can you give me a roadmap for learning, I have experience in Laravel
Ex097
And best wishes
jj
How do I give a docker based project it’s own url after hosting it on the server?
Anonymous
You&amp;amp;amp;amp;amp;amp;amp;#39;re using sessions to create a shopping cart. You have a Product model and a Variant model, where you specify the color and size of your products in the Variant model. This approach allows you to have products with different colors and sizes, as well as different prices. Is this the correct method according to you?
Anonymous
During implementation I&amp;amp;amp;amp;amp;amp;amp;#39;have many difficulties. It is my first experience with e-commerce site
Ex097
do_something()
vaishnav
Css cheat sheet
Wanda
I am working on a django celery aws s3 project where while doing celery shared task I am getting file access denied what should I do?
Jussy
Hello Everybody, I'm having a small issue on django I got this error from one of my form :
line 1025, in _get_flatchoices
for choice, value in self.choices:
^^^^^^^^^^^^^
ValueError: too many values to unpack (expected 2)
The form inherited from ModelForm. In the fields I have a choice field that's present. I would also like to clarify that when I create the project and all his component it was working fine and from
Kishan
I need to deploy the django rest project in the cpanel
Any have idea about this?
Doragonsureiyā
Css cheat sheet
This is not a Django specific question, please delete your offtopic message.
If it's a Python related question go to @Python group, otherwise please move to @PythonOfftopic group and ask there.
Abolfazl
Hi, can anyone suggest me an expert django course and a good beginner django course (just for reviewing)
Alex
Alex
corey Schafer
Novend
Novend