Monday, March 30, 2020

Re: Django ORM query with joins

thanks that worked 

On Monday, March 30, 2020 at 7:49:07 PM UTC+5:30, Suraj Thapa FC wrote:
Sorry its like this...
posts.objects.values('id', 'details', 'user__name' )

On Mon, 30 Mar 2020, 7:46 pm Suraj Thapa FC, <surajt...@gmail.com> wrote:
posts.model.values('id', 'details', 'user__name' )

On Mon, 30 Mar 2020, 5:26 pm Anoop Thiparala, <anthi...@gmail.com> wrote:
I need help with a django query...I have two models

1) POSTS
==>id
==>details
==>user(foreign key to user table)

2) USER
==>id
==>email
==>name

SQL VERSION: SELECT POSTS.ID, POSTS.DETAILS, USER.NAME FROM POSTS, USER WHERE POSTS.USER == USER.ID;

I require these details in the same queryset...is it possible ? 

--
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/c59d7b0c-834f-47fe-8162-5e34f42c51f9%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e63a421a-1f40-4368-9d05-430518db6e4b%40googlegroups.com.

Re: Having issue sending email when model is save and not updated.

Hi,

Use Django signals presave and postsave.


Regards,
Sunil H N
-sent from MacBook Air











On 31-Mar-2020, at 01:48, Isaac Imafidon <isaac.imafidon69@gmail.com> wrote:

Am working on an ecommerce project and i want to be able to do two things before the model save .
1) I want to update the cost of an item
2) I want to send two  email to the receiver . One when the object just gets created while the other when the object gets updated.
I go through django documentation about pre_save signal and post_save signal but don't really understand it.

This is my model
 
class Item(models.Model):
    # set of possible order statuses
    ITEM_STATUSES = (('PICK UP','PICK UP'), #default
        ('IN TRANSIT','IN TRANSIT'), # To let ur customer know their order is now been process
        ('DELIVERED','DELIVERED'),#Now delivered to them

        )
    cost = models.DecimalField(max_digits=10, decimal_places=2)
    sender_name = models.CharField(max_length=150)
    sender_email = models.EmailField()
    receiver_name = models.CharField(max_length=150)
    receiver_email = models.EmailField()

Before this model is save i want to update the cost by adding 10% of the cost variable to create a new cost that will be shown in the view also i want to send email to receiver_email  variable. Once the user update the model i want to still add my 10% to the cost and instead of sending email one, i will send email two.
Something like this

....Model as before
if just_created :
   update the cost by 10% before save to the database
   send email 1 carrying the new cost variable and the receiver name to receiver email
   then save()
else:
   update the cost by 10% before saving to the database
   send email 2 carrying the new cost variable and the receiver name to receiver email
   then save()

Please guys i really need your help in this.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a9ed1900-b432-49f2-8899-4a96a02eef66%40googlegroups.com.

Re: drawing a venn diagram with css and html

thanks for all your input,
for those that might need to use this i managed this way;
solution is to write css on style.css and them import it on a template
that the cms will use and it works like a charm

reply here for details and i will help those in need of it.
cheers

On 3/28/20, Perceval Maturure <drperceval@gmail.com> wrote:
> Hi team
>
> i am trying to draw a diagramm using css and html on my cms but it
> displays raw css and text. any ideas?
> --
> *Perceval Maturure*
>
> *083 303 9423*
>


--
*Perceval Maturure*

*083 303 9423*

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFZtZmB3s9qMSOxHj%3DTVGZm-eXk7tR%3DuqqtU56MrUPFRAFK8zQ%40mail.gmail.com.

Re: HTML code not being read

Here is the change I suggest:

https://gist.github.com/tubaman/bf49949f8a9369ad3db1f56d5ce7dbc0/revisions

On 3/30/20 1:03 PM, Jeff Waters wrote:
@login_required
def add_comment(request, image_id):
    new_comment = None
    template_name = 'add_comment.html'
    image = get_object_or_404(Picture, id=image_id)
    comment = image.comments.filter(active=True)
    new_comment = None
    # Comment posted
    if request.method == 'POST':
        comment_form = CommentForm(data=request.POST)
        if comment_form.is_valid():
            # Create Comment object and don't save to database yet
            new_comment = comment_form.save(commit=False)
            # Assign the current post to the comment
            new_comment.post = post
            # Save the comment to the database
            new_comment.save()
    else:
        comment_form = CommentForm()
    context = {'image': image,'comment': comment, 'new_comment': new_comment,'comment_form': comment_form}
    return render(request, template_name, context)

Extending Django admin delete confirmation page

Greetings,

I am wondering if it is possible to extend Django Admin's delete confirmation page. I tried the following but the received template does not exist error page.
% extends 'admin:admin/delete_confirmation.html' %}
I refer to this website which stated it is possible to do so https://book.huihoo.com/django/en/1.0/chapter17/index.html
I want to add a few custom actions which should require confirmation before proceeding. 

Thanks and Regards
Gagan Deep

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c71f8c6c-c218-4dbc-ab4f-6c5c814d5a3a%40googlegroups.com.

Re: HTML code not being read

Let's see your url.py

On Mon, Mar 30, 2020, 10:03 PM Jeff Waters <watersjg@gmail.com> wrote:
I've modified my code a bit to try (unsuccessfully!) to get this working.

My views.py is now as follows:

@login_required
def add_comment(request, image_id):
    new_comment = None
    template_name = 'add_comment.html'
    image = get_object_or_404(Picture, id=image_id)
    comment = image.comments.filter(active=True)
    new_comment = None
    # Comment posted
    if request.method == 'POST':
        comment_form = CommentForm(request.POST)
        if comment_form.is_valid():
            # Create Comment object and don't save to database yet
            new_comment = comment_form.save(commit=False)
            # Assign the current post to the comment
            new_comment.post = post
            # Save the comment to the database
            new_comment.save()
    else:
        comment_form = CommentForm()

    context = {'image': image,'comment': comment, 'new_comment': new_comment,'comment_form': comment_form}

    return render(request, template_name, context)

My html code for the gallery is now:

            <h2>comments</h2>
                {% if not comments %}
                No comments
                {% endif %}
                {% for comment in comment %}
                <div class="comments" style="padding: 10px;">
                    <p class="font-weight-bold">
                        <h4>Comment by</h4> {{ comment.user }}
                        <span class=" text-muted font-weight-normal">
                            {{ comment.created_on }}
                        </span>
                    </p>
                    {{ comment.body | linebreaks }}
                </div>
                {% endfor %}

The problem I now have is that I now get the following error message: Reverse for 'add_comment' with arguments '('',)' not found. 1 pattern(s) tried: ['add_comment/(?P<image_id>[0-9]+)$']

Any suggestions would be much appreciated.

Thanks

Jeff

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e2212e12-d379-4bcb-8c96-eff4c89c5245%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHyB84rnc11SOpJJvwtyzoWkf%3D77jBjzKNctBeN3S%3D9ipKRa%3Dg%40mail.gmail.com.

Re: HTML code not being read

I've modified my code a bit to try (unsuccessfully!) to get this working.

My views.py is now as follows:

@login_required
def add_comment(request, image_id):
new_comment = None
template_name = 'add_comment.html'
image = get_object_or_404(Picture, id=image_id)
comment = image.comments.filter(active=True)
new_comment = None
# Comment posted
if request.method == 'POST':
comment_form = CommentForm(request.POST)
if comment_form.is_valid():
# Create Comment object and don't save to database yet
new_comment = comment_form.save(commit=False)
# Assign the current post to the comment
new_comment.post = post
# Save the comment to the database
new_comment.save()
else:
comment_form = CommentForm()

context = {'image': image,'comment': comment, 'new_comment': new_comment,'comment_form': comment_form}

return render(request, template_name, context)

My html code for the gallery is now:

<h2>comments</h2>
{% if not comments %}
No comments
{% endif %}
{% for comment in comment %}
<div class="comments" style="padding: 10px;">
<p class="font-weight-bold">
<h4>Comment by</h4> {{ comment.user }}
<span class=" text-muted font-weight-normal">
{{ comment.created_on }}
</span>
</p>
{{ comment.body | linebreaks }}
</div>
{% endfor %}

The problem I now have is that I now get the following error message: Reverse for 'add_comment' with arguments '('',)' not found. 1 pattern(s) tried: ['add_comment/(?P<image_id>[0-9]+)$']

Any suggestions would be much appreciated.

Thanks

Jeff

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e2212e12-d379-4bcb-8c96-eff4c89c5245%40googlegroups.com.