Re: Django ORM query with joins

2020-03-30 Thread Anoop Thiparala
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,  > wrote:
>
>> posts.model.values('id', 'details', 'user__name' )
>>
>> On Mon, 30 Mar 2020, 5:26 pm Anoop Thiparala, > > 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+unsubscr...@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.

2020-03-30 Thread Sunil H N
Hi,

Use Django signals presave and postsave.


Regards,
Sunil H N
sunil.kann...@gmail.com 
-sent from MacBook Air











> On 31-Mar-2020, at 01:48, Isaac Imafidon  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+unsubscr...@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
>  
> .

-- 
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/4961AB2B-ED05-4201-B26E-5067A5B7600E%40gmail.com.


Re: drawing a venn diagram with css and html

2020-03-30 Thread Perceval Maturure
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  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+unsubscr...@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

2020-03-30 Thread Ryan Nowakowski

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)


--
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/bacdf5da-e1cb-09c4-568d-a0bc70362e1a%40fattuba.com.


Extending Django admin delete confirmation page

2020-03-30 Thread Gagan Deep
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+unsubscr...@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

2020-03-30 Thread Luqman Shofuleji
Let's see your url.py

On Mon, Mar 30, 2020, 10:03 PM Jeff Waters  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:
>
> comments
> {% if not comments %}
> No comments
> {% endif %}
> {% for comment in comment %}
> 
> 
> Comment by {{ comment.user }}
> 
> {{ comment.created_on }}
> 
> 
> {{ comment.body | linebreaks }}
> 
> {% 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[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+unsubscr...@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+unsubscr...@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

2020-03-30 Thread Jeff Waters
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:

comments
{% if not comments %}
No comments
{% endif %}
{% for comment in comment %}


Comment by {{ comment.user }}

{{ comment.created_on }}


{{ comment.body | linebreaks }}

{% 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[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+unsubscr...@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.


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

2020-03-30 Thread Isaac Imafidon
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+unsubscr...@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: HTML code not being read

2020-03-30 Thread Aly_34_04 MR_34_04
show me your views 

On Monday, March 30, 2020 at 5:13:49 PM UTC+3, Jeff Waters wrote:
>
> Hi
>
> I have written some code that allows users of a website to comment on 
> photos in a picture gallery, using a form. However, when I test the code, 
> no comments are displayed.
>
> It would appear that Django is not processing the following code (from my 
> HTML file for the photo gallery), given that 'Comment by' is not displayed 
> on screen:
>
> {% for comment in comments %}
> 
> 
> Comment by {{ comment.user }}
> 
> {{ comment.created_on }}
> 
> 
> {{ comment.body | linebreaks }}
> 
> {% endfor %}
>
> Does anyone have any suggestions as to how I can fix this, please?
>
> Thank you.
>
> 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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/85705553-9cd4-49e2-878e-8c0a903bc79f%40googlegroups.com.


guys django form doesn't appear, what could I do?

2020-03-30 Thread Aly_34_04 MR_34_04


[image: Capture.JPG]
template:
  


  Bildiris bermek




  

  
Modal title

  

  
  

{% csrf_token %}
{{ form }}

  
  
Close
Save changes
  

  




Gözlet






django form:

from django import forms
from .models import Post


class PostForm(forms.ModelForm):
class Meta:
model = Post
fields = '__all__'


def __init__(self, *args, **kwargs):
super().__init__(*args,**kwargs)
for field in self.fields:
self.fields[field].widget['class'] = 'form-control'



django views:

from django.shortcuts import render
from .models import Post
from .forms import PostForm


def add_post(request):
if request.method == 'POST':
form = PostForm(request.POST)
if form.is_valid():
form.save()
template = 'home.html'
context = {'form': PostForm(),}
return render(request,template,context)

-


django urls

from django.urls import path
from .import views

urlpatterns = [
path('',views.home, name="home"),
path('detail/',views.detail_page, name="detail"),
path('',views.add_post, name="home"),
]




django models:

from django.db import models


class Post(models.Model):
title = models.CharField(max_length=50)
date = models.DateTimeField(auto_now=True)
text = models.TextField()


class Meta:
ordering = ('-date',)


def __str__(self):
return self.title



-- 
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/fa7e9ab5-974a-4752-be7d-b60b31277f88%40googlegroups.com.


Re: HTML code not being read

2020-03-30 Thread Jeff Waters
Thanks guys

I previously had 'comments' in the plural in views.py, but had the same 
problem. 

Am I right in thinking that Django recognises that 'comments' is the plural of 
'comment', so if it knows from the view what a comment is, it knows what 
comments are?

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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/055a99d8-a18f-4235-b133-feb9dd206930%40googlegroups.com.


Re: HTML code not being read

2020-03-30 Thread Luqman Shofuleji
What you passed to the context in your views.py is 'comment', but you are
looping through 'comments' in the template

On Mon, Mar 30, 2020, 3:52 PM Jeff Waters  wrote:

> Hi
>
> Thanks for getting back to me.
>
> This is from my views.py:
>
> @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.comment.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 = {'comment_form': comment_form, 'image': image,'comment':
> comment, 'new_comment': new_comment,'comment_form': comment_form}
>
> return render(request, template_name, context)
>
> Does that look correct to you?
>
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/7f92c0a3-07cc-4b33-ba37-e32bc24c5386%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/CAHyB84o4GGgDBEPSo0wNFd1F%3DK9dXk3MzVjRFm%2BrmBtYOq%2BBZQ%40mail.gmail.com.


Re: HTML code not being read

2020-03-30 Thread Ryan Nowakowski
Your view context uses 'comment'(singular), while your template uses 
'comments'(plural).  I'd chnage your view context to match the template.


On 3/30/20 9:51 AM, Jeff Waters wrote:

Hi

Thanks for getting back to me.

This is from my views.py:

@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.comment.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 = {'comment_form': comment_form, 'image': image,'comment': 
comment, 'new_comment': new_comment,'comment_form': comment_form}

 return render(request, template_name, context)

Does that look correct to you?

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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c105b434-0ffa-8861-17d3-f7824a861f4d%40fattuba.com.


Re: Custom login in django

2020-03-30 Thread Will Meyers
We'd need more info, but most likely the actual token is not being sent to
the template properly. See this

thread for suggestions.

On Mon, Mar 30, 2020 at 11:18 AM Kushal Neupane  wrote:

> Forbidden (403)
>
> CSRF verification failed. Request aborted.
> Help
>
> Reason given for failure:
>
> CSRF token missing or 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.
>
> [image: Capture.PNG]
>
>
> --
> 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/7de9d86d-5607-43c5-8462-185a04bcc648%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/CACCQDfDo64nJnPgMG%3DdX93wHAbkWUyjyTTtXQdptPJn6jLZQzg%40mail.gmail.com.


Re: Custom login in django

2020-03-30 Thread Kasper Laudrup

https://stackoverflow.com/help/how-to-ask

--
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/1f83fadc-9ec1-dfc1-82b2-eb4178e109a7%40stacktrace.dk.


Custom login in django

2020-03-30 Thread Kushal Neupane
 Forbidden (403) 

CSRF verification failed. Request aborted.
Help 

Reason given for failure:

CSRF token missing or 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.

[image: Capture.PNG]


-- 
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/7de9d86d-5607-43c5-8462-185a04bcc648%40googlegroups.com.


Re: HTML code not being read

2020-03-30 Thread Jeff Waters
Hi 

I'm not sure what you mean by 'Have you all ready use a content that define 
your content'.

I'm new to Django, so am not familiar with all of the terminology yet.

Can you elaborate please?

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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5e97ab38-2663-4943-b4b8-bf6e3ea744a5%40googlegroups.com.


Issue with passing parameters in urls

2020-03-30 Thread aniket kamthe
Hey All, 
I have been watching your youtube tutorials and have been stuck on an issue 
for a while now. Can you help me out pls - 

I am trying to pass a parameter via a button in an HTML file and using that 
in the next link to access a specific set of entries from the database - 

HTML File code - 

{% for thread in object %}
  
  {{ thread.name }}
  Something
  
{% endfor %}

URLs files code - 

path('message//', views.message, name='message'),

Views files code 

def message(request, threadid):
  if request.method == 'POST':
print(request.POST.get('message'))
m = messages(message=request.POST.get('message'), thread_id='00', 
likes='00', Message_flags='00')
m.save();
if (request.method == 'POST') and ("like" in request.POST):
  print("hi")
data = messages.objects.all()
context = {
  'object': data
}
return render(request, 'mysite/message.html', context)
  else:
data = messages.objects.all()
context = {
  'object': data
}
return render(request, 'mysite/message.html', context)

But I get this error, idk how to resolve this one - 

[image: image.png]
Pls let me know If you are able to figure out the problem. 

-- 
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/deae3154-4d36-438a-9669-5698d319ed27%40googlegroups.com.


Re: HTML code not being read

2020-03-30 Thread Jeff Waters
Hi 

Thanks for getting back to me.

This is from my views.py:

@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.comment.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 = {'comment_form': comment_form, 'image': image,'comment': comment, 
'new_comment': new_comment,'comment_form': comment_form}

return render(request, template_name, context)

Does that look correct to you?

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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7f92c0a3-07cc-4b33-ba37-e32bc24c5386%40googlegroups.com.


Re: HTML code not being read

2020-03-30 Thread LGBS fine soul coders
Have you all ready use a content that define your content

On Mon, 30 Mar 2020, 17:14 Jeff Waters,  wrote:

> Hi
>
> I have written some code that allows users of a website to comment on
> photos in a picture gallery, using a form. However, when I test the code,
> no comments are displayed.
>
> It would appear that Django is not processing the following code (from my
> HTML file for the photo gallery), given that 'Comment by' is not displayed
> on screen:
>
> {% for comment in comments %}
> 
> 
> Comment by {{ comment.user }}
> 
> {{ comment.created_on }}
> 
> 
> {{ comment.body | linebreaks }}
> 
> {% endfor %}
>
> Does anyone have any suggestions as to how I can fix this, please?
>
> Thank you.
>
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4666d2ec-e4d8-492d-8203-03dfecd29d6a%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/CAKNQJk5Mys3t7WLeBatbZ7Mg8Bj4WaMabELqmWGKiUvHBguQ_Q%40mail.gmail.com.


Re: HTML code not being read

2020-03-30 Thread Luqman Shofuleji
The problem might not be from the HTML template but the View.
All the HTML elements within your for loop will not display if there are no
records to loop through in "comments"

On Mon, Mar 30, 2020, 3:14 PM Jeff Waters  wrote:

> Hi
>
> I have written some code that allows users of a website to comment on
> photos in a picture gallery, using a form. However, when I test the code,
> no comments are displayed.
>
> It would appear that Django is not processing the following code (from my
> HTML file for the photo gallery), given that 'Comment by' is not displayed
> on screen:
>
> {% for comment in comments %}
> 
> 
> Comment by {{ comment.user }}
> 
> {{ comment.created_on }}
> 
> 
> {{ comment.body | linebreaks }}
> 
> {% endfor %}
>
> Does anyone have any suggestions as to how I can fix this, please?
>
> Thank you.
>
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4666d2ec-e4d8-492d-8203-03dfecd29d6a%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/CAHyB84rnKyBKR8rZbV2zij5QfK0FyA9F6DWCRo2v01QD48T%3DDQ%40mail.gmail.com.


Re: Django ORM query with joins

2020-03-30 Thread Suraj Thapa FC
Sorry its like this...
posts.objects.values('id', 'details', 'user__name' )

On Mon, 30 Mar 2020, 7:46 pm Suraj Thapa FC,  wrote:

> posts.model.values('id', 'details', 'user__name' )
>
> On Mon, 30 Mar 2020, 5:26 pm Anoop Thiparala, 
> 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-users+unsubscr...@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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPjsHcHEMn1QWQiFUKD5rgY3yu9_muxWGj9STop8cz83pUkTcg%40mail.gmail.com.


Re: Django ORM query with joins

2020-03-30 Thread Suraj Thapa FC
posts.model.values('id', 'details', 'user__name' )

On Mon, 30 Mar 2020, 5:26 pm Anoop Thiparala,  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-users+unsubscr...@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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPjsHcHsWSUuEgKdy%2BXQL0NLn4dzTco-t_SQuOcVzBAZm4_XCw%40mail.gmail.com.


HTML code not being read

2020-03-30 Thread Jeff Waters
Hi

I have written some code that allows users of a website to comment on photos in 
a picture gallery, using a form. However, when I test the code, no comments are 
displayed.

It would appear that Django is not processing the following code (from my HTML 
file for the photo gallery), given that 'Comment by' is not displayed on screen:

{% for comment in comments %}


Comment by {{ comment.user }}

{{ comment.created_on }}


{{ comment.body | linebreaks }}

{% endfor %}

Does anyone have any suggestions as to how I can fix this, please?

Thank you.

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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4666d2ec-e4d8-492d-8203-03dfecd29d6a%40googlegroups.com.


Re: Looking for Django developers to work on a new and an existing project with our team

2020-03-30 Thread Satish Pal
Hi

I have total of 2 years of experience and I am interested to join your team.
please check my Linkedin profile
https://www.linkedin.com/in/satish-kumar-2230b3158/

Thanks in Advance.

On Mon, Mar 30, 2020 at 8:51 AM Phako Perez <13.phak...@gmail.com> wrote:

> Hi,
>
> I’m also interested to join your team, have 3+ years working with python
> Currently I’m teaching python to a group in order them to improve theirs
> career
>
> Thanks in advance
>
> Sent from my iPhone
>
> On 29 Mar 2020, at 20:48, chinna  wrote:
>
> 
> Hi,
>
> I am Premkumar having 3 years of experience in web and rest api
> development using python and Django. I would like to join your team
>
> On Sun, Mar 29, 2020 at 11:26 PM Lax Nayak  wrote:
>
>> I am looking for a django developer who has expertise in building
>> enterprise grade solutions.
>>
>>
>> --
>> 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/f93f06b0-883c-4477-9d73-cc429a43380d%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/CAG%3DmdoCaGy%3DTWh0CY04_TBo8uG__4UWnd8sfWYLOZ8fapfZ%3DCA%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/5C30197E-FCE7-4BE8-B169-4E9E74F4EBF3%40gmail.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/CALzNJXmFb3cSFpEmYs2yB502x%2BB9DtNkDT_L2hqxvmvTPx08jA%40mail.gmail.com.


Django ORM query with joins

2020-03-30 Thread Anoop Thiparala
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-users+unsubscr...@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.


Re: Looking for Django developers to work on a new and an existing project with our team

2020-03-30 Thread ABHISHEK SAHU
Hi,

I can join your team immediately. I have 2 years of experience working with
python and web development using django framework.

Thanks and Regards,
Abhishek

On Sun, Mar 29, 2020, 11:26 PM Lax Nayak  wrote:

> I am looking for a django developer who has expertise in building
> enterprise grade solutions.
>
>
> --
> 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/f93f06b0-883c-4477-9d73-cc429a43380d%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/CAOpO%3DWKxWd-TmPeuZ9v1%2B2xwuR0-j9c_TzDAf2m63XDubXhQ4w%40mail.gmail.com.


Re: Is there any possibility integrate django and tkinter?

2020-03-30 Thread Anoop Thiparala
One possible way would be to make an API using django rest framework and 
use API calls from your tkinter application

On Sunday, March 29, 2020 at 11:00:07 PM UTC+5:30, Walter santos wrote:
>
> Hi
>
> Is there any possibility integrate django and tkinter?
>

-- 
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/75ee9c1c-0fa7-4b64-b9c9-4365c7cd7497%40googlegroups.com.


Re: Form not displaying

2020-03-30 Thread Jeff Waters
Will do, 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/0969e788-8cea-40a0-acc8-655bfa8ab2ce%40googlegroups.com.


Re: Form not displaying

2020-03-30 Thread Ernest Thuku
There in your template...that closing form tag...is it a typing error?I
can't see the second closing tag
On Mar 30, 2020 13:23, "Ernest Thuku"  wrote:

> Try this
> On Mar 30, 2020 12:58, "Jeff Waters"  wrote:
>
>> Thanks Ernest.
>>
>> I'm not sure I follow (forgive me, I am very new to Django).
>>
>> Given that template_name is defined earlier in the method as
>> 'add_comment.html', surely what I've written is equivalent to:
>>
>> return render(request, add_comment.html, {'image': image,
>>'comments': comments,
>>'new_comment': new_comment,
>>'comment_form': comment_form})
>>
>> What should the code be instead?
>>
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/django-users/8e5fcc67-5a91-4371-a51a-9860a6cc78e3%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/CAPsfuodXhoe2DXi4t3fmmSoBV1kGzS%2BpxKU5cPhC8Ux%2BHF%3D%2BFw%40mail.gmail.com.


Re: Form not being published

2020-03-30 Thread Metehan Gülaç
There is no problem in the code. Look again at the quote and typos in the 
form class. and do a trial with this view:

from django.shortcuts import render
from django.http import HttpResponseRedirect
from .forms import CommentForm


def my_view(request):
if request.method == 'POST':
form = CommentForm(request.POST)
if form.is_valid():
return HttpResponseRedirect('/thanks/')
else:
form = CommentForm()
return render(request, 'index.html', {'comment_form': form})





30 Mart 2020 Pazartesi 05:12:30 UTC+3 tarihinde Jeff Waters yazdı:
>
> I am creating a website using Django. I'd like to give users the chance to 
> comment on pictures they have posted. I have created a comment model and a 
> comment form, and put the following code into the HTML document for the 
> photo gallery: 
>
> Leave a comment 
>  
> {{ comment_form.as_p }} 
> {% csrf_token %} 
> Submit 
>  
>
> However, the form is not displaying - there is nothing between 'Leave a 
> comment' and the submit button on the page. I don't understand this as my 
> form in forms.py appears to be configured correctly: 
>
> class CommentForm(forms.ModelForm): 
> body = forms.CharField(help_text="What is your comment?", 
> widget=forms.TextInput(attrs={'size': '1000'}), 
>required=True) 
>
> class Meta: 
> model = Comment 
> fields = ('body',) 
> def as_p(self): 
> # Returns this form rendered as HTML s. 
> return self._html_output( 
> normal_row='%(field)s', 
> error_row='%s', 
> row_ender='', 
> help_text_html=' %s', 
> errors_on_separate_row=True)` 
>
> So does my model in models.py: 
>
> class Comment(models.Model): 
> COMMENT_MAX_LENGTH = 1000 
> image = models.ForeignKey(Picture, on_delete=models.CASCADE, 
> related_name="comments") 
> user = models.ForeignKey(UserProfile, on_delete=models.CASCADE) 
> body = models.TextField(max_length=COMMENT_MAX_LENGTH) 
> created_on = models.DateTimeField(auto_now_add=True) 
> active = models.BooleanField(default=False) 
>
> class Meta: 
> ordering = ['created_on'] 
>
> def __str__(self): 
> return 'Comment {} by {}'.format(self.body, self.user) 
>
> When I go into the source code on the site, it shows that the form is 
> hidden. Also, when I change comment_form.as_p to something random, no error 
> messages are generated. It's like something is causing Django to skip past 
> that bit of code. 
>
> I'd really appreciate any suggestions anyone could please offer. 
>
> 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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/989ca9da-02bb-4596-ad34-dfd2ded2e6a1%40googlegroups.com.


Re: Form not displaying

2020-03-30 Thread Jeff Waters
Thanks Ernest.

I'm not sure I follow (forgive me, I am very new to Django).

Given that template_name is defined earlier in the method as 
'add_comment.html', surely what I've written is equivalent to:

return render(request, add_comment.html, {'image': image,
   'comments': comments,
   'new_comment': new_comment,
   'comment_form': comment_form})

What should the code be instead?

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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8e5fcc67-5a91-4371-a51a-9860a6cc78e3%40googlegroups.com.


Re: Forienkey to same table

2020-03-30 Thread Motaz Hejaze
What are the usages lf such a technique ??

On Mon, 30 Mar 2020, 11:16 am Metehan Gülaç,  wrote:

> first of all, you can remove the *1. id (pK)* line. django already create
> this field for you in background. I think you want to reference id field of
> A table to himself; it is known as *recursive relationship*. Speaking the
> which, you can use:
>
> models.ForeignKey('self', on_delete=models.CASCADE)
>
>
> 30 Mart 2020 Pazartesi 05:45:11 UTC+3 tarihinde Mohsen Pahlevanzadeh yazdı:
>>
>> I have table A with my following fields:
>> 1. id (PK)
>> 2. fname (text)
>> 3. name (text)
>> 4. A_id (integer)
>>
>> I have problem with 4th field, Because it has to refrenced to id
>> field. I can't implement it into Django.
>>
>> How can I write model class for above table in models.py ?
>>
>> --mohsen
>>
> --
> 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/ebd316df-e70f-4e7e-ba02-55fede43909e%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/CAHV4E-d4fu8x7Qb8XsUimsZY_YS1BM6%3DbOP0ZyQNYwwB546LUQ%40mail.gmail.com.


Re: Forienkey to same table

2020-03-30 Thread Metehan Gülaç
first of all, you can remove the *1. id (pK)* line. django already create 
this field for you in background. I think you want to reference id field of 
A table to himself; it is known as *recursive relationship*. Speaking the 
which, you can use:

models.ForeignKey('self', on_delete=models.CASCADE)


30 Mart 2020 Pazartesi 05:45:11 UTC+3 tarihinde Mohsen Pahlevanzadeh yazdı:
>
> I have table A with my following fields: 
> 1. id (PK) 
> 2. fname (text) 
> 3. name (text) 
> 4. A_id (integer) 
>
> I have problem with 4th field, Because it has to refrenced to id 
> field. I can't implement it into Django. 
>
> How can I write model class for above table in models.py ? 
>
> --mohsen 
>

-- 
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/ebd316df-e70f-4e7e-ba02-55fede43909e%40googlegroups.com.


Re: Form not displaying

2020-03-30 Thread Ernest Thuku
In the views why have you used templane_name while you not using class
based views...try and change that to render the template using request
On Mar 30, 2020 11:55, "Jeff Waters"  wrote:

> Sure. It's as follows:
>
> @login_required
> def add_comment(request, image_id):
> template_name = 'add_comment.html'
> image = get_object_or_404(Picture, id=image_id)
> comments = 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()
>
> return render(request, template_name, {'image': image,
>'comments': comments,
>'new_comment': new_comment,
>'comment_form': comment_form})
>
>
>
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/8e0f5a28-7a48-4037-aba5-ea591a81d397%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/CAPsfuofgALu7-qZFeVyxxr4LJLtAwnsFhnYvsOSD6QMBmH17bw%40mail.gmail.com.


Re: Form not displaying

2020-03-30 Thread Jeff Waters
Sure. It's as follows:

@login_required
def add_comment(request, image_id):
template_name = 'add_comment.html'
image = get_object_or_404(Picture, id=image_id)
comments = 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()

return render(request, template_name, {'image': image,
   'comments': comments,
   'new_comment': new_comment,
   'comment_form': comment_form})



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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8e0f5a28-7a48-4037-aba5-ea591a81d397%40googlegroups.com.


Re: Form not displaying

2020-03-30 Thread Ernest Thuku
Can you display your views please?
On Mar 30, 2020 05:13, "Jeff Waters"  wrote:

> Apologies if I'm posting this twice - my original message isn't displayed
> in the list of messages.
>
> I am creating a website using Django. I'd like to give users the chance to
> comment on pictures they have posted. I have created a comment model and a
> comment form, and put the following code into the HTML document for the
> photo gallery:
>
> Leave a comment
> 
> {{ comment_form.as_p }}
> {% csrf_token %}
> Submit
>  However, the form is not displaying - there is nothing between 'Leave a
> comment' and the submit button on the page. I don't understand this as my
> form in forms.py appears to be configured correctly:
>
> class CommentForm(forms.ModelForm):
> body = forms.CharField(help_text="What is your comment?",
> widget=forms.TextInput(attrs={'size': '1000'}),
>required=True)
>
> class Meta:
> model = Comment
> fields = ('body',)
> def as_p(self):
> # Returns this form rendered as HTML s.
> return self._html_output(
> normal_row='%(field)s',
> error_row='%s',
> row_ender='',
> help_text_html=' %s',
> errors_on_separate_row=True)`
> So does my model in models.py:
>
> class Comment(models.Model):
> COMMENT_MAX_LENGTH = 1000
> image = models.ForeignKey(Picture, on_delete=models.CASCADE,
> related_name="comments")
> user = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
> body = models.TextField(max_length=COMMENT_MAX_LENGTH)
> created_on = models.DateTimeField(auto_now_add=True)
> active = models.BooleanField(default=False)
>
> class Meta:
> ordering = ['created_on']
>
> def __str__(self):
> return 'Comment {} by {}'.format(self.body, self.user)
>
> When I go into the source code on the site, it shows that the form is
> hidden. Also, when I change comment_form.as_p to something random, no error
> messages are generated. It's like something is causing Django to skip past
> that bit of code.
>
> I'd really appreciate any suggestions anyone could please offer.
>
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/ac7ac525-9bc4-4043-a142-b97b1d3d0e5c%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/CAPsfuofTW8RywcqoK6T4SZz%2BqtkAWHHg7UAoshXOupOh6nj_WQ%40mail.gmail.com.