Re: Customizing Django built-in views such as LoginView

2020-05-29 Thread אורי
Thank you.
אורי
u...@speedy.net


On Fri, May 29, 2020 at 3:57 PM Augusto Destrero 
wrote:

> I would choose the second option and define a LoginView subclass in the
> views.py module.
> The outcome is exactly the same, but I'd prefer to have my views all
> defined in views.py file.
> Adding too much logic in the urls.py module IMHO is not a good idea and it
> makes the view less extendable in the future.
>
> Augusto
> www.guguweb.com
>
> On Friday, May 29, 2020 at 2:31:17 PM UTC+2, Uri wrote:
>>
>> Django users,
>>
>> Which way is preferred to customize Django built-in views such as
>> LoginView:
>>
>> - Define a line in urls.py:
>>
>> path(route='login/', view=views.django_auth_views.LoginView.as_view(
>> template_name='accounts/login.html', authentication_form=forms.LoginForm,
>> extra_context=None, redirect_authenticated_user=True), name='login'),
>>
>> Where, views.py contains:
>>
>> from django.contrib.auth import views as django_auth_views
>>
>>
>> *Or:*
>>
>> In views.py, define a new class:
>>
>> class LoginView(django_auth_views.LoginView):
>> template_name = 'accounts/login.html'
>> authentication_form = LoginForm
>> extra_context = None
>> redirect_authenticated_user = True
>>
>> And then, define in urls.py:
>>
>> path(route='login/', view=views.LoginView.as_view(), name='login'),
>>
>>
>> Will both ways work the same, and is one of them preferred from a
>> software engineering / programming perspective?
>>
>> Thanks,
>> Uri.
>> אורי
>> u...@speedy.net
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8b10a5cf-5f33-4035-98b2-54ac0b84f25e%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABD5YeHUGHNrm2jEEKqrj%2BBo2ygd_jr%3DZqqoPy02ZFE3AU0qvA%40mail.gmail.com.


Re: Can You please help me out!!!

2020-05-29 Thread meera gangani
I Want to implement Mark all a read in notification!!
So What should i do!!
Can you explain me a little bit of this!

On Sat, May 30, 2020 at 8:46 AM meera gangani 
wrote:

> Thank you So much for helping me out!!
> Thanks a lot
>
> Meera Gangani
>
> On Fri, May 29, 2020 at 5:08 PM Sencer Hamarat 
> wrote:
>
>> Hi Meera,
>>
>> You have only one record because of you are using .latest() method in the
>> query.
>>
>> If you want to last 3 or 4 object ordered by descending date, you should
>> write queryset like this:
>>
>> notifications = Notification.objects.all().order_by('-date')[0:x]  # The
>> 'x' could be 3 or 4 by your choice.
>>
>> An pass the notifications to request context in 'render_to_response'
>> call. {'notifications': notifications}
>>
>> The you have to iterate notifications in template via for loop. For
>> example;
>>
>> {% for notification in notifications %}
>> notification.title
>> notification.message
>> notification.date
>> {% endfor %}
>>
>> Saygılarımla,
>> Sencer HAMARAT
>>
>>
>>
>> On Fri, May 29, 2020 at 1:59 PM meera gangani 
>> wrote:
>>
>>> i want to fetch last 3 records for notification!!
>>> But I only fetch last 1 record.
>>>
>>> Can you please help me out!!!
>>> Can i use filters??
>>>
>>> And my model fields are:
>>> title=
>>> message=
>>> date=
>>>
>>> And i want to fetch last 3-4 records
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CANaPPPJVprm5gE0FNFWqPDGdW_ciq15JQXLmjVHinJkHPwRdqQ%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CACp8TZh3iD4M2%3Ddq4NOrPTpOzAYCFxx_kduS6%2BK%2BEG2kPDFkYA%40mail.gmail.com
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANaPPPLnRv2matia%2B6Xm9j0cSoNHYWnn8HMt08ojmqxQOrXvCg%40mail.gmail.com.


Re: Can You please help me out!!!

2020-05-29 Thread meera gangani
Thank you So much for helping me out!!
Thanks a lot

Meera Gangani

On Fri, May 29, 2020 at 5:08 PM Sencer Hamarat 
wrote:

> Hi Meera,
>
> You have only one record because of you are using .latest() method in the
> query.
>
> If you want to last 3 or 4 object ordered by descending date, you should
> write queryset like this:
>
> notifications = Notification.objects.all().order_by('-date')[0:x]  # The
> 'x' could be 3 or 4 by your choice.
>
> An pass the notifications to request context in 'render_to_response' call.
> {'notifications': notifications}
>
> The you have to iterate notifications in template via for loop. For
> example;
>
> {% for notification in notifications %}
> notification.title
> notification.message
> notification.date
> {% endfor %}
>
> Saygılarımla,
> Sencer HAMARAT
>
>
>
> On Fri, May 29, 2020 at 1:59 PM meera gangani 
> wrote:
>
>> i want to fetch last 3 records for notification!!
>> But I only fetch last 1 record.
>>
>> Can you please help me out!!!
>> Can i use filters??
>>
>> And my model fields are:
>> title=
>> message=
>> date=
>>
>> And i want to fetch last 3-4 records
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CANaPPPJVprm5gE0FNFWqPDGdW_ciq15JQXLmjVHinJkHPwRdqQ%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACp8TZh3iD4M2%3Ddq4NOrPTpOzAYCFxx_kduS6%2BK%2BEG2kPDFkYA%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CANaPPP%2BwXHHeQfZOrqAOfwPfLwKhGUiV4v4Nbu%3DnRYNeWS-qrQ%40mail.gmail.com.


Re: A learner following a Mosh Tutorial on Django and having a problem saving a product to SQLite

2020-05-29 Thread Matt D

>
> Hello Iain,
>
 I am also working on Mosh's python tutorial and I'm having the same 
problems that you expressed in this chat. Did you delete the migrations 
through pycharm or through your computer to make it work?
Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5cf0bf92-5773-43a3-a273-4ccfdb61734c%40googlegroups.com.


AttributeError when returning post.title in a comment model

2020-05-29 Thread Ahmed Khairy


I was working on a comment section for post and was getting an 
AttributeError when I return return '{}-{}'.format(self.post.title, 
str(self.user.username)) in the comment model

I am trying to link users and posts to the comment I am getting the same 
error

Here is the Models.py

class Comment(models.Model):
post = models.ForeignKey(Post, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
content = models.TextField(max_length=160)
timestamp = models.DateTimeField(auto_now_add=True)

def __str__(self):
return '{}-{}'.format(self.post.title, str(self.user.username))

Here is the views.py:

class PostDetailView(DetailView):
model = Post
template_name = "post_detail.html"

def get_context_data(self, *args, **kwargs):
context = super(PostDetailView, self).get_context_data()
post = get_object_or_404(Post, slug=self.kwargs['slug'])
comments = Comment.objects.filter(post=post).order_by('-id')
total_likes = post.total_likes()
liked = False
if post.likes.filter(id=self.request.user.id).exists():
liked = True

if self.request.method == 'POST':
comment_form = CommentForm(self.request.POST or None)
if comment_form.is_valid():
content = self.request.POST.get('content')
comment = Comment.objects.create(
post=post, user=request.user, content=content)
comment.save()
return HttpResponseRedirect("post_detail.html")
else:
comment_form = CommentForm()

context["total_likes"] = total_likes
context["liked"] = liked
context["comments"] = comments
context["comment_form"] = comment_form
return context


class PostCommentCreateView(LoginRequiredMixin, CreateView):
model = Comment
form_class = CommentForm


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9e84bb03-ca66-4517-ab34-8d723a457b9f%40googlegroups.com.


Re: help on jwt

2020-05-29 Thread ola neat
ea i checked the permission_classes variable, i got attached the error
message displayed

On Thu, May 21, 2020 at 4:34 PM Chetan Ganji  wrote:

> If you post the error, someone can help you better.
>
> Did you look into authentication_classes variable of the endpoint ???
>
> Regards,
> Chetan Ganji
> +91-900-483-4183
> ganji.che...@gmail.com
> http://ryucoder.in
>
>
> On Thu, May 21, 2020 at 6:48 PM ola neat  wrote:
>
>> halo, i'm working on implementing JWT for user registration but i'm
>> having issue with that, when i make post request for signup, i get an
>> authentication  detail no provided err, below is my code, hope anyone can
>> help out
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAHLKn73JY3zZFQbAir-t5As%3D5VUm0Sn-AC3CqAeoPqXQ%3Dp4_zA%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMKMUjvpN%3D8BuduhuGoVkE9Sikw4Xagqo8h8HeKFJQgRcOQxTg%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHLKn71po25esnP-8Dq3jnaQ--qJ6_iZWNFzcbisN_jdR1MUyg%40mail.gmail.com.


Soy nuevo en el Foro

2020-05-29 Thread Mateo Carbajal Montiel


Hello, good day everyone on the forum, I am new to the topic, but I have the 
basic notions and it makes me quite interesting, I would ask you to recommend 
books, documents, to understand the topic further, excellent day, greetings.

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/43843f42-4e13-42fa-8315-656af0897c9e%40googlegroups.com.


Re: filter on multiple tables

2020-05-29 Thread Soumen Khatua
Thank You, for your guidance.I think I'm very close to this problem.

Thank you once again.

‪On Fri, May 29, 2020 at 9:56 AM ‫אורי‬‎  wrote:‬

> Hi Soumen,
>
> You can filter on another table by using __, for
> example:
>
> User.objects.filter(profile__profiles__institute_name="Example")
>
> Or:
>
> User.objects.filter(profile__profiles__institute_name__in=["Example 1",
> "Example 2"])
> אורי
> u...@speedy.net
>
>
> On Thu, May 28, 2020 at 11:27 PM Soumen Khatua 
> wrote:
>
>> Actually I want to filter all users those are matched with currently
>> logged in users based on location or education details like maybe
>> institute_name or specialization. Is it possible to search in multiple
>> tables?!
>> I almost spent 2 days but still I stuck in the position.
>> Any help would be appreciated.
>>
>> Thank You
>>
>> Regards,
>> Soumen
>>
>>
>>
>>
>> *class Location(models.Model):name = models.CharField(max_length =
>> 15)*
>>
>>
>>
>>
>>
>>
>>
>> *class Profile(models.Model):user = models.OneToOneField(
>> settings.AUTH_USER_MODEL,on_delete = models.CASCADE,
>> related_name="profile")location =
>> models.ManyToManyField(Location,related_name = 'user_locations')*
>>
>>
>>
>>
>> *class Education(models.Model):profile = models.ForeignKey(Profile,
>> on_delete=models.CASCADE,related_name="profiles")institute_name =
>> models.CharField(max_length = 250)specialization =
>> models.CharField(max_length = 100)*
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAPUw6WZqX9oqutYfGJqAwCswY_00VfTmf624ypypAr6saS61Nw%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABD5YeFfHWDEkTFwMFocApuG3ejYY5QjqHHd_86wNNc-JoWP4g%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPUw6WZGO9bXukP9VX_k%3DOW0U1Vbz_885cH5i%2BhH8n-nFXz%2BQw%40mail.gmail.com.


Re: Optimized Query

2020-05-29 Thread Soumen Khatua
Hi,

Yeah, but whenever I'm trying to iterate a loop on all these qs. I'm
getting an *error too many sql variables.* I know I'm doing something
wrong,but I'm not able to find the error.


Thank you for your response and time.

Regards,
Soumen

‪On Fri, May 29, 2020 at 5:49 PM ‫אורי‬‎  wrote:‬

> They both work for both.
> אורי
> u...@speedy.net
>
>
> On Fri, May 29, 2020 at 12:47 PM Sencer Hamarat 
> wrote:
>
>> I thought select_related works for only FK/M2M and prefetch_related works
>> for only reverse relations, doesn't it?
>>
>> Saygılarımla,
>> Sencer HAMARAT
>>
>>
>>
>> ‪On Fri, May 29, 2020 at 7:32 AM ‫אורי‬‎  wrote:‬
>>
>>> Hi Soumen,
>>>
>>> Sometimes prefetch_related is much faster and more efficient than
>>> select_related. I usually prefer to use prefetch_related.
>>>
>>> Uri.
>>> אורי
>>> u...@speedy.net
>>>
>>>
>>> On Thu, May 28, 2020 at 12:42 AM Soumen Khatua <
>>> soumenkhatua...@gmail.com> wrote:
>>>
 Actually I want to fetch all users from User table and users location
 from Location table which is many to many relation from same Profile table.
 Is it possible???

 On Thu 28 May, 2020, 2:54 AM Soumen Khatua, 
 wrote:

> Now I'm facing one problem whenever I'm trying to iterate a loop I'm
> getting too many SQL variables. Actually after iterating the loop I want 
> to
> render all the value in the template.
> if could you resolve this it would be very good for me.
> Thank you for your time and response
>
> Regards,
> Soumen
>
>
> On Thu, May 28, 2020 at 2:12 AM Chetan Ganji 
> wrote:
>
>>
>> Profile.objects.filter().select_related("user").prefetch_related("location")
>>
>> On Thu, May 28, 2020, 2:01 AM Soumen Khatua <
>> soumenkhatua...@gmail.com> wrote:
>>
>>> I also know about this concept but I don't how I can achieve it,
>>> Could you give me an example?
>>> Suppose I have:
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> *class Profile(models.Model):user = models.OneToOneField(
>>> settings.AUTH_USER_MODEL,on_delete = models.CASCADE,
>>> related_name="profile")location = 
>>> models.ManyToManyField(Location)*
>>>
>>>
>>> Thank you
>>>
>>> Regards,
>>> Soumen
>>>
>>> On Wed, May 27, 2020 at 7:20 PM Chetan Ganji 
>>> wrote:
>>>
 select_related for fk and prefetch_related for m2m in django, you
 can chain them together

 Regards,
 Chetan Ganji
 +91-900-483-4183
 ganji.che...@gmail.com
 http://ryucoder.in


 On Wed, May 27, 2020 at 4:51 PM Soumen Khatua <
 soumenkhatua...@gmail.com> wrote:

> Hi Folks,
> I have many to many relationships and Foreign Key in the table,
> I'm using select_realted(foreign key filed name) to optimize the 
> query but
> I want to fetch many to many and foreign key at the same time , How I 
> can
> do this in very optimized way?
>
> Thank You
> Regards,
> Soumen
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPUw6Wb6f-BCwUZfvgzGtsrbV1seq1iGbXyuqoH%3DKxZrJ2EyLg%40mail.gmail.com
> 
> .
>
 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it,
 send an email to django-users+unsubscr...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/CAMKMUju19j7apa1pXZQcZTY-6ThTJC%3DAL2eQhtO7DL2oTk6Oog%40mail.gmail.com
 
 .

>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it,
>>> send an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAPUw6WZXtTJssu6SwO8_BiTDxDnzJtKYy9j1hQsMR74jKYC6aA%40mail.gmail.com
>>> 

Re: filter on multiple tables

2020-05-29 Thread Soumen Khatua
Hi,

whenever I'm trying to filter as per your convention I'm getting some error
like FieldError:
*Eg.* *profile =
Profile.objects.filter(education__profile__institute_name="IIT KGP")*

of course, I'm getting this error because Profile is working here as a
Foreign Key, in Education table.

actually I want to fetch all the users those are from the same Institution
or Specialization or location.


Thank you for your response and time.

Regards,
Soumen


‪On Fri, May 29, 2020 at 9:56 AM ‫אורי‬‎  wrote:‬

> Hi Soumen,
>
> You can filter on another table by using __, for
> example:
>
> User.objects.filter(profile__profiles__institute_name="Example")
>
> Or:
>
> User.objects.filter(profile__profiles__institute_name__in=["Example 1",
> "Example 2"])
> אורי
> u...@speedy.net
>
>
> On Thu, May 28, 2020 at 11:27 PM Soumen Khatua 
> wrote:
>
>> Actually I want to filter all users those are matched with currently
>> logged in users based on location or education details like maybe
>> institute_name or specialization. Is it possible to search in multiple
>> tables?!
>> I almost spent 2 days but still I stuck in the position.
>> Any help would be appreciated.
>>
>> Thank You
>>
>> Regards,
>> Soumen
>>
>>
>>
>>
>> *class Location(models.Model):name = models.CharField(max_length =
>> 15)*
>>
>>
>>
>>
>>
>>
>>
>> *class Profile(models.Model):user = models.OneToOneField(
>> settings.AUTH_USER_MODEL,on_delete = models.CASCADE,
>> related_name="profile")location =
>> models.ManyToManyField(Location,related_name = 'user_locations')*
>>
>>
>>
>>
>> *class Education(models.Model):profile = models.ForeignKey(Profile,
>> on_delete=models.CASCADE,related_name="profiles")institute_name =
>> models.CharField(max_length = 250)specialization =
>> models.CharField(max_length = 100)*
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAPUw6WZqX9oqutYfGJqAwCswY_00VfTmf624ypypAr6saS61Nw%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABD5YeFfHWDEkTFwMFocApuG3ejYY5QjqHHd_86wNNc-JoWP4g%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPUw6WazA6k1MHjUWiMWvEPU9HnitRK7bBzq-aQVOrP9w84o-Q%40mail.gmail.com.


Re: function model which generate a code for model field

2020-05-29 Thread Derek
I would not assume what "previous" means. Rather use post_save to get the 
actual ID of the current recording.

On Friday, 29 May 2020 12:43:19 UTC+2, Anselme SERI wrote:
>
> Hello Derek,
> Is it possible to retrieve the id of the previous recording from this 
> function? If possible I could increment it to get the id of the current 
> recording.
> Anselme S.
>
> Le ven. 29 mai 2020 à 06:08, Derek > a 
> écrit :
>
>> The suggested code will not work because, at this point, the "id" has not 
>> yet been generated by the database (unlike the other data which is 
>> typically entered by the user).
>>
>> You will need to move this code to a post_save signal function - 
>> https://docs.djangoproject.com/en/3.0/ref/signals/#post-save - where the 
>> "instance" object can be used to get the "id" value.
>>
>> On Wednesday, 27 May 2020 14:22:41 UTC+2, Kasper Laudrup wrote:
>>>
>>> Hi Anselme, 
>>>
>>>
>>> On 27/05/2020 13.33, Anselme SERI wrote: 
>>> > 
>>> > What I want to do is fill in the 'code' field of my 'Diploma' 
>>> template. 
>>> > For example, the first record of the model will have the value 
>>> > 'BAC1' in the 'code' field, the second 'BAC2', , 
>>> 'BAC01653' 
>>> > . 
>>> > The approach I have chosen to achieve this objective consists in 
>>> > defining a function in the model which will retrieve the value of the 
>>> > last id of the last record, increment it then concatenate it to the 
>>> > chain to obtain the value of the code field of the new recording. code 
>>> = 
>>> > chain + (lastid + 1) with chain = 'BAC000 ..'. I hope it's clear now? 
>>> > 
>>>
>>> There might be better ways to do this, but I would override the save() 
>>> method of your model with something like: 
>>>
>>> def save(self, *args, **kwargs): 
>>>  self.code = 'BAC{:05}'.format(self.id) 
>>>  super(MyModel, self).save(*args, **kwargs) 
>>>
>>> Untested, but hopefully you get the idea. 
>>>
>>> Kind regards, 
>>>
>>> Kasper Laudrup 
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/bad64876-a692-463a-99af-5d491841d5a1%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1d759e75-e933-4fcf-9d82-8c52c9e080fc%40googlegroups.com.


Re: How models.Manager is working behind the scene and calling different serialize methods?

2020-05-29 Thread django-newbie
Ohk, I got it now..
Thanks for clarifying this.

My further doubts in continuation of this are.

1. For confirmation, ModelName.objects.all() calls get_queryset() method, 
while ModelName.objects.get calls get() method internally.

2. In above code to override default serialize method of BasicUserUpdate 
for get_queryset() method, 
We have to do 2 things.
1. Inherit default models.Manager and override get_queryset() method.
2. Inherit  models.QuerySet and override default serialize method.

Honestly it seems overkill for this problem.
Can u please suggest alternative straight forward way to do it in model 
only.

On Friday, May 29, 2020 at 3:34:39 PM UTC+5:30, Sencer Hamarat wrote:
>
> I believe, the method "get_query*set*" name is explains what you want to 
> know.
>
> If you filter or fetch every thing with django query, it returns queryset.
> The .get() query on the other hand, returns a single object.
>
> Saygılarımla,
> Sencer HAMARAT
>
>
>
> On Fri, May 29, 2020 at 4:43 AM django-newbie  > wrote:
>
>> Hi, 
>> I am new to django and going through a tutorial and now confused with one 
>> particular implementation.
>>
>> models.py
>>
>> import json
>> from django.core.serializers import serialize
>>
>> from django.db import models
>> from django.conf import settings
>>
>> # Create your models here.
>>
>>
>> def upload_update_image(instance, filename):
>> return "updates/{owner}/{filename}".format(owner=instance.owner, 
>> filename=filename)
>>
>> class UpdateQuerySet(models.QuerySet):
>>  
>> def serialize(self):
>> print("UpdateQuerySet serialize")
>> print(self.values("owner", "content", "image"))
>> list_values = list(self.values("owner", "content", "image"))
>> return json.dumps(list_values)
>>
>>
>> class UpdateManager(models.Manager):
>>
>> def get_queryset(self):
>> print('get_queryset method')
>> return UpdateQuerySet(self.model, using=self._db)
>>
>>
>> class BasicUserUpdate(models.Model):
>> owner = 
>> models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE)
>> content = models.TextField(blank=True,null=True)
>> image = 
>> models.ImageField(blank=True,null=True,upload_to=upload_update_image,)
>> updated = models.DateTimeField(auto_now=True)
>> timestamp = models.DateTimeField(auto_now_add=True)
>>
>> def __str__(self):
>> return self.content or ''
>>
>> objects = UpdateManager()
>>
>>
>> def serialize(self):
>> print("BasicUserUpdate serialize")
>> try:
>> image = self.image.url
>> except:
>> image = ""
>> data = {
>> "content": self.content,
>> "owner": self.owner.id,
>> "image": image
>> }
>> data = json.dumps(data)
>> return data
>>
>>   
>> views.py
>>
>> from basic.models import BasicUserUpdate
>> from django.views import View
>> from django.http import HttpResponse
>>
>>
>> class BasicUserUpdateListView(View):
>> def get(self, request, *args, **kwargs):
>> qs = BasicUserUpdate.objects.all()
>> json_data = qs.serialize()
>> return HttpResponse(json_data, content_type='application/json')
>>
>> class BasicUserUpdateDetailView(View):
>>
>> def get(self, request,id, *args, **kwargs):
>> qs = BasicUserUpdate.objects.get(id=id)
>> json_data = qs.serialize()
>> return HttpResponse(json_data, content_type='application/json')
>>
>> ]
>>
>>
>> *At run time calling ListView, get below print messages*
>> get_queryset method
>> UpdateQuerySet serialize
>>
>> *At run time calling DetailView, get below print messages*
>> get_queryset method
>> BasicUserUpdate serialize
>>
>>
>> *How Django is identifying which serialize method to be called? *
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/3fdc04cb-5da9-4d6a-8935-3ebf9409196b%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/560f2715-eae2-4dd7-9172-f71acd5368d7%40googlegroups.com.


Re: Customizing Django built-in views such as LoginView

2020-05-29 Thread Augusto Destrero
I would choose the second option and define a LoginView subclass in the 
views.py module.
The outcome is exactly the same, but I'd prefer to have my views all 
defined in views.py file.
Adding too much logic in the urls.py module IMHO is not a good idea and it 
makes the view less extendable in the future.

Augusto
www.guguweb.com

On Friday, May 29, 2020 at 2:31:17 PM UTC+2, Uri wrote:
>
> Django users,
>
> Which way is preferred to customize Django built-in views such as 
> LoginView:
>
> - Define a line in urls.py:
>
> path(route='login/', view=views.django_auth_views.LoginView.as_view(
> template_name='accounts/login.html', authentication_form=forms.LoginForm, 
> extra_context=None, redirect_authenticated_user=True), name='login'),
>
> Where, views.py contains:
>
> from django.contrib.auth import views as django_auth_views
>
>
> *Or:*
>
> In views.py, define a new class:
>
> class LoginView(django_auth_views.LoginView):
> template_name = 'accounts/login.html'
> authentication_form = LoginForm
> extra_context = None
> redirect_authenticated_user = True
>
> And then, define in urls.py:
>
> path(route='login/', view=views.LoginView.as_view(), name='login'),
>
>
> Will both ways work the same, and is one of them preferred from a software 
> engineering / programming perspective?
>
> Thanks,
> Uri.
> אורי
> u...@speedy.net 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8b10a5cf-5f33-4035-98b2-54ac0b84f25e%40googlegroups.com.


Re: Parallel or split payment options using paypal

2020-05-29 Thread Akshat Zala
Hi John 

I agree with Kasper.

Regards,

Akshat

On Thursday, 28 May 2020 01:31:03 UTC+5:30, Kasper Laudrup wrote:
>
> Hi John, 
>
> On 27/05/2020 19.06, John McClain wrote: 
> > Hello All, 
> > 
> > Can anyone provide a method to split payments via paypal. I basically 
> > want to earn a commission on the sale and pass the balance to the seller 
> > through my marketplace. 
> > 
>
> Maybe this would be a better place to ask: 
>
> https://www.paypal.com/us/smarthelp/home 
>
> Kind regards, 
>
> Kasper Laudrup 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c3b6f605-5a23-4e6a-96ae-02d5a67971cb%40googlegroups.com.


Customizing Django built-in views such as LoginView

2020-05-29 Thread אורי
Django users,

Which way is preferred to customize Django built-in views such as LoginView:

- Define a line in urls.py:

path(route='login/', view=views.django_auth_views.LoginView.as_view(
template_name='accounts/login.html', authentication_form=forms.LoginForm,
extra_context=None, redirect_authenticated_user=True), name='login'),

Where, views.py contains:

from django.contrib.auth import views as django_auth_views


*Or:*

In views.py, define a new class:

class LoginView(django_auth_views.LoginView):
template_name = 'accounts/login.html'
authentication_form = LoginForm
extra_context = None
redirect_authenticated_user = True

And then, define in urls.py:

path(route='login/', view=views.LoginView.as_view(), name='login'),


Will both ways work the same, and is one of them preferred from a software
engineering / programming perspective?

Thanks,
Uri.
אורי
u...@speedy.net

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABD5YeGvexcpJTgnHtAJcmX7LL0z_xi1siU7qi-6hBwiNRrOEA%40mail.gmail.com.


Re: Optimized Query

2020-05-29 Thread אורי
They both work for both.
אורי
u...@speedy.net


On Fri, May 29, 2020 at 12:47 PM Sencer Hamarat 
wrote:

> I thought select_related works for only FK/M2M and prefetch_related works
> for only reverse relations, doesn't it?
>
> Saygılarımla,
> Sencer HAMARAT
>
>
>
> ‪On Fri, May 29, 2020 at 7:32 AM ‫אורי‬‎  wrote:‬
>
>> Hi Soumen,
>>
>> Sometimes prefetch_related is much faster and more efficient than
>> select_related. I usually prefer to use prefetch_related.
>>
>> Uri.
>> אורי
>> u...@speedy.net
>>
>>
>> On Thu, May 28, 2020 at 12:42 AM Soumen Khatua 
>> wrote:
>>
>>> Actually I want to fetch all users from User table and users location
>>> from Location table which is many to many relation from same Profile table.
>>> Is it possible???
>>>
>>> On Thu 28 May, 2020, 2:54 AM Soumen Khatua, 
>>> wrote:
>>>
 Now I'm facing one problem whenever I'm trying to iterate a loop I'm
 getting too many SQL variables. Actually after iterating the loop I want to
 render all the value in the template.
 if could you resolve this it would be very good for me.
 Thank you for your time and response

 Regards,
 Soumen


 On Thu, May 28, 2020 at 2:12 AM Chetan Ganji 
 wrote:

>
> Profile.objects.filter().select_related("user").prefetch_related("location")
>
> On Thu, May 28, 2020, 2:01 AM Soumen Khatua 
> wrote:
>
>> I also know about this concept but I don't how I can achieve it,
>> Could you give me an example?
>> Suppose I have:
>>
>>
>>
>>
>>
>>
>>
>> *class Profile(models.Model):user = models.OneToOneField(
>> settings.AUTH_USER_MODEL,on_delete = models.CASCADE,
>> related_name="profile")location = 
>> models.ManyToManyField(Location)*
>>
>>
>> Thank you
>>
>> Regards,
>> Soumen
>>
>> On Wed, May 27, 2020 at 7:20 PM Chetan Ganji 
>> wrote:
>>
>>> select_related for fk and prefetch_related for m2m in django, you
>>> can chain them together
>>>
>>> Regards,
>>> Chetan Ganji
>>> +91-900-483-4183
>>> ganji.che...@gmail.com
>>> http://ryucoder.in
>>>
>>>
>>> On Wed, May 27, 2020 at 4:51 PM Soumen Khatua <
>>> soumenkhatua...@gmail.com> wrote:
>>>
 Hi Folks,
 I have many to many relationships and Foreign Key in the table, I'm
 using select_realted(foreign key filed name) to optimize the query but 
 I
 want to fetch many to many and foreign key at the same time , How I 
 can do
 this in very optimized way?

 Thank You
 Regards,
 Soumen

 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it,
 send an email to django-users+unsubscr...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/CAPUw6Wb6f-BCwUZfvgzGtsrbV1seq1iGbXyuqoH%3DKxZrJ2EyLg%40mail.gmail.com
 
 .

>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it,
>>> send an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAMKMUju19j7apa1pXZQcZTY-6ThTJC%3DAL2eQhtO7DL2oTk6Oog%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it,
>> send an email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAPUw6WZXtTJssu6SwO8_BiTDxDnzJtKYy9j1hQsMR74jKYC6aA%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMKMUjth%3DNm%2BUa74bz1PiRYFGhKU-PER9_Y_XQdHRQ23KMbp7Q%40mail.gmail.com
> 

Re: Templates vs. source code

2020-05-29 Thread אורי
Thank you.
אורי
u...@speedy.net


On Fri, May 29, 2020 at 12:56 PM Sencer Hamarat 
wrote:

> Hi Uri,
> Never expose whole settings anytime. settings is always includes sensitive
> data. At least DB access key and Django's secret value.
> This attitude is highly vulnerable. Anyone could access those sensitive
> data via response headers if you don't play settings without cautious.
>
> Saygılarımla,
> Sencer HAMARAT
>
>
>
> ‪On Fri, May 29, 2020 at 7:11 AM ‫אורי‬‎  wrote:‬
>
>> Django users,
>>
>> There was a discussion in Stack Overflow related to an answer of mine -
>> how to access settings from templates in Django [
>> https://stackoverflow.com/a/53953578/1412564]. And I would like to know
>> - is it generally unsafe to expose all my settings to templates and why?
>> Should I use the updated answer and expose only specific settings to
>> templates? Because if a hacker can change my templates, they can also
>> change my .py files, and then they can give themselves any access they want
>> to. So what is better - expose all my settings to templates or only
>> specific settings which I consider safe?
>>
>> Thanks,
>> Uri.
>> אורי
>> u...@speedy.net
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CABD5YeEmHtPHMKs7ub42eeTQR8_XfDUGwyCtn9XGmvZ0JyFfwQ%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACp8TZhg3ES2eaUaqP0GYAXyBiWW%2BzWgB2-QEJHX%3DQi13-C5BA%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABD5YeE9bmNXEP8Z6fKia6sh7Gu4SAO5P4Guai7fk4Z%2BkBmJqA%40mail.gmail.com.


Re: Can You please help me out!!!

2020-05-29 Thread Sencer Hamarat
Hi Meera,

You have only one record because of you are using .latest() method in the
query.

If you want to last 3 or 4 object ordered by descending date, you should
write queryset like this:

notifications = Notification.objects.all().order_by('-date')[0:x]  # The
'x' could be 3 or 4 by your choice.

An pass the notifications to request context in 'render_to_response' call.
{'notifications': notifications}

The you have to iterate notifications in template via for loop. For example;

{% for notification in notifications %}
notification.title
notification.message
notification.date
{% endfor %}

Saygılarımla,
Sencer HAMARAT



On Fri, May 29, 2020 at 1:59 PM meera gangani 
wrote:

> i want to fetch last 3 records for notification!!
> But I only fetch last 1 record.
>
> Can you please help me out!!!
> Can i use filters??
>
> And my model fields are:
> title=
> message=
> date=
>
> And i want to fetch last 3-4 records
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CANaPPPJVprm5gE0FNFWqPDGdW_ciq15JQXLmjVHinJkHPwRdqQ%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACp8TZh3iD4M2%3Ddq4NOrPTpOzAYCFxx_kduS6%2BK%2BEG2kPDFkYA%40mail.gmail.com.


Re: function model which generate a code for model field

2020-05-29 Thread Anselme SERI
Hello Derek,
Is it possible to retrieve the id of the previous recording from this
function? If possible I could increment it to get the id of the current
recording.
Anselme S.

Le ven. 29 mai 2020 à 06:08, Derek  a écrit :

> The suggested code will not work because, at this point, the "id" has not
> yet been generated by the database (unlike the other data which is
> typically entered by the user).
>
> You will need to move this code to a post_save signal function -
> https://docs.djangoproject.com/en/3.0/ref/signals/#post-save - where the
> "instance" object can be used to get the "id" value.
>
> On Wednesday, 27 May 2020 14:22:41 UTC+2, Kasper Laudrup wrote:
>>
>> Hi Anselme,
>>
>>
>> On 27/05/2020 13.33, Anselme SERI wrote:
>> >
>> > What I want to do is fill in the 'code' field of my 'Diploma' template.
>> > For example, the first record of the model will have the value
>> > 'BAC1' in the 'code' field, the second 'BAC2', , 'BAC01653'
>> > .
>> > The approach I have chosen to achieve this objective consists in
>> > defining a function in the model which will retrieve the value of the
>> > last id of the last record, increment it then concatenate it to the
>> > chain to obtain the value of the code field of the new recording. code
>> =
>> > chain + (lastid + 1) with chain = 'BAC000 ..'. I hope it's clear now?
>> >
>>
>> There might be better ways to do this, but I would override the save()
>> method of your model with something like:
>>
>> def save(self, *args, **kwargs):
>>  self.code = 'BAC{:05}'.format(self.id)
>>  super(MyModel, self).save(*args, **kwargs)
>>
>> Untested, but hopefully you get the idea.
>>
>> Kind regards,
>>
>> Kasper Laudrup
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/bad64876-a692-463a-99af-5d491841d5a1%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACbA33oeQZxJ%2B59-6iX_8NDYb7tGCbMN4VSez8OTAnoFgrLfKA%40mail.gmail.com.


Re: How models.Manager is working behind the scene and calling different serialize methods?

2020-05-29 Thread Sencer Hamarat
I believe, the method "get_query*set*" name is explains what you want to
know.

If you filter or fetch every thing with django query, it returns queryset.
The .get() query on the other hand, returns a single object.

Saygılarımla,
Sencer HAMARAT



On Fri, May 29, 2020 at 4:43 AM django-newbie 
wrote:

> Hi,
> I am new to django and going through a tutorial and now confused with one
> particular implementation.
>
> models.py
>
> import json
> from django.core.serializers import serialize
>
> from django.db import models
> from django.conf import settings
>
> # Create your models here.
>
>
> def upload_update_image(instance, filename):
> return "updates/{owner}/{filename}".format(owner=instance.owner, 
> filename=filename)
>
> class UpdateQuerySet(models.QuerySet):
>
> def serialize(self):
> print("UpdateQuerySet serialize")
> print(self.values("owner", "content", "image"))
> list_values = list(self.values("owner", "content", "image"))
> return json.dumps(list_values)
>
>
> class UpdateManager(models.Manager):
>
> def get_queryset(self):
> print('get_queryset method')
> return UpdateQuerySet(self.model, using=self._db)
>
>
> class BasicUserUpdate(models.Model):
> owner = 
> models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE)
> content = models.TextField(blank=True,null=True)
> image = 
> models.ImageField(blank=True,null=True,upload_to=upload_update_image,)
> updated = models.DateTimeField(auto_now=True)
> timestamp = models.DateTimeField(auto_now_add=True)
>
> def __str__(self):
> return self.content or ''
>
> objects = UpdateManager()
>
>
> def serialize(self):
> print("BasicUserUpdate serialize")
> try:
> image = self.image.url
> except:
> image = ""
> data = {
> "content": self.content,
> "owner": self.owner.id,
> "image": image
> }
> data = json.dumps(data)
> return data
>
>
> views.py
>
> from basic.models import BasicUserUpdate
> from django.views import View
> from django.http import HttpResponse
>
>
> class BasicUserUpdateListView(View):
> def get(self, request, *args, **kwargs):
> qs = BasicUserUpdate.objects.all()
> json_data = qs.serialize()
> return HttpResponse(json_data, content_type='application/json')
>
> class BasicUserUpdateDetailView(View):
>
> def get(self, request,id, *args, **kwargs):
> qs = BasicUserUpdate.objects.get(id=id)
> json_data = qs.serialize()
> return HttpResponse(json_data, content_type='application/json')
>
> ]
>
>
> *At run time calling ListView, get below print messages*
> get_queryset method
> UpdateQuerySet serialize
>
> *At run time calling DetailView, get below print messages*
> get_queryset method
> BasicUserUpdate serialize
>
>
> *How Django is identifying which serialize method to be called? *
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3fdc04cb-5da9-4d6a-8935-3ebf9409196b%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACp8TZjA1okZy2-0pAk5f4A6uCxThxHnobtDsnOG%2BJ8_LXk%2BBA%40mail.gmail.com.


Re: Templates vs. source code

2020-05-29 Thread Sencer Hamarat
Hi Uri,
Never expose whole settings anytime. settings is always includes sensitive
data. At least DB access key and Django's secret value.
This attitude is highly vulnerable. Anyone could access those sensitive
data via response headers if you don't play settings without cautious.

Saygılarımla,
Sencer HAMARAT



‪On Fri, May 29, 2020 at 7:11 AM ‫אורי‬‎  wrote:‬

> Django users,
>
> There was a discussion in Stack Overflow related to an answer of mine -
> how to access settings from templates in Django [
> https://stackoverflow.com/a/53953578/1412564]. And I would like to know -
> is it generally unsafe to expose all my settings to templates and why?
> Should I use the updated answer and expose only specific settings to
> templates? Because if a hacker can change my templates, they can also
> change my .py files, and then they can give themselves any access they want
> to. So what is better - expose all my settings to templates or only
> specific settings which I consider safe?
>
> Thanks,
> Uri.
> אורי
> u...@speedy.net
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CABD5YeEmHtPHMKs7ub42eeTQR8_XfDUGwyCtn9XGmvZ0JyFfwQ%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACp8TZhg3ES2eaUaqP0GYAXyBiWW%2BzWgB2-QEJHX%3DQi13-C5BA%40mail.gmail.com.


Re: Optimized Query

2020-05-29 Thread Sencer Hamarat
I thought select_related works for only FK/M2M and prefetch_related works
for only reverse relations, doesn't it?

Saygılarımla,
Sencer HAMARAT



‪On Fri, May 29, 2020 at 7:32 AM ‫אורי‬‎  wrote:‬

> Hi Soumen,
>
> Sometimes prefetch_related is much faster and more efficient than
> select_related. I usually prefer to use prefetch_related.
>
> Uri.
> אורי
> u...@speedy.net
>
>
> On Thu, May 28, 2020 at 12:42 AM Soumen Khatua 
> wrote:
>
>> Actually I want to fetch all users from User table and users location
>> from Location table which is many to many relation from same Profile table.
>> Is it possible???
>>
>> On Thu 28 May, 2020, 2:54 AM Soumen Khatua, 
>> wrote:
>>
>>> Now I'm facing one problem whenever I'm trying to iterate a loop I'm
>>> getting too many SQL variables. Actually after iterating the loop I want to
>>> render all the value in the template.
>>> if could you resolve this it would be very good for me.
>>> Thank you for your time and response
>>>
>>> Regards,
>>> Soumen
>>>
>>>
>>> On Thu, May 28, 2020 at 2:12 AM Chetan Ganji 
>>> wrote:
>>>

 Profile.objects.filter().select_related("user").prefetch_related("location")

 On Thu, May 28, 2020, 2:01 AM Soumen Khatua 
 wrote:

> I also know about this concept but I don't how I can achieve it, Could
> you give me an example?
> Suppose I have:
>
>
>
>
>
>
>
> *class Profile(models.Model):user = models.OneToOneField(
> settings.AUTH_USER_MODEL,on_delete = models.CASCADE,
> related_name="profile")location = 
> models.ManyToManyField(Location)*
>
>
> Thank you
>
> Regards,
> Soumen
>
> On Wed, May 27, 2020 at 7:20 PM Chetan Ganji 
> wrote:
>
>> select_related for fk and prefetch_related for m2m in django, you can
>> chain them together
>>
>> Regards,
>> Chetan Ganji
>> +91-900-483-4183
>> ganji.che...@gmail.com
>> http://ryucoder.in
>>
>>
>> On Wed, May 27, 2020 at 4:51 PM Soumen Khatua <
>> soumenkhatua...@gmail.com> wrote:
>>
>>> Hi Folks,
>>> I have many to many relationships and Foreign Key in the table, I'm
>>> using select_realted(foreign key filed name) to optimize the query but I
>>> want to fetch many to many and foreign key at the same time , How I can 
>>> do
>>> this in very optimized way?
>>>
>>> Thank You
>>> Regards,
>>> Soumen
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it,
>>> send an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAPUw6Wb6f-BCwUZfvgzGtsrbV1seq1iGbXyuqoH%3DKxZrJ2EyLg%40mail.gmail.com
>>> 
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it,
>> send an email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAMKMUju19j7apa1pXZQcZTY-6ThTJC%3DAL2eQhtO7DL2oTk6Oog%40mail.gmail.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPUw6WZXtTJssu6SwO8_BiTDxDnzJtKYy9j1hQsMR74jKYC6aA%40mail.gmail.com
> 
> .
>
 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to django-users+unsubscr...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/CAMKMUjth%3DNm%2BUa74bz1PiRYFGhKU-PER9_Y_XQdHRQ23KMbp7Q%40mail.gmail.com
 
 .

>>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.

Re: function model which generate a code for model field

2020-05-29 Thread Derek
The suggested code will not work because, at this point, the "id" has not 
yet been generated by the database (unlike the other data which is 
typically entered by the user).

You will need to move this code to a post_save signal function - 
https://docs.djangoproject.com/en/3.0/ref/signals/#post-save - where the 
"instance" object can be used to get the "id" value.

On Wednesday, 27 May 2020 14:22:41 UTC+2, Kasper Laudrup wrote:
>
> Hi Anselme, 
>
>
> On 27/05/2020 13.33, Anselme SERI wrote: 
> > 
> > What I want to do is fill in the 'code' field of my 'Diploma' template. 
> > For example, the first record of the model will have the value 
> > 'BAC1' in the 'code' field, the second 'BAC2', , 'BAC01653' 
> > . 
> > The approach I have chosen to achieve this objective consists in 
> > defining a function in the model which will retrieve the value of the 
> > last id of the last record, increment it then concatenate it to the 
> > chain to obtain the value of the code field of the new recording. code = 
> > chain + (lastid + 1) with chain = 'BAC000 ..'. I hope it's clear now? 
> > 
>
> There might be better ways to do this, but I would override the save() 
> method of your model with something like: 
>
> def save(self, *args, **kwargs): 
>  self.code = 'BAC{:05}'.format(self.id) 
>  super(MyModel, self).save(*args, **kwargs) 
>
> Untested, but hopefully you get the idea. 
>
> Kind regards, 
>
> Kasper Laudrup 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bad64876-a692-463a-99af-5d491841d5a1%40googlegroups.com.