Re: More controls on createsuperuser

2019-04-28 Thread JJ Zolper
What if maybe after the command is run once it then is required to check a 
list of approved subsequent admins before allowing creation of an account? 
Some kind of list stored in the admin that is required to be populated 
following the first admin, or maybe 3 admins?

On Sunday, April 28, 2019 at 11:24:57 PM UTC-4, JJ Zolper wrote:
>
> All,
>
> Curious what people think about more thought and control going into who 
> can run the createsuperuser method?
>
> For example say there's models that I don't want anyone to touch except 
> myself as a superuser. Is it not plausible that even if I make a Django 
> Group around that model that someone could still run createsuperuser and 
> give themselves the ability to have full control?
>
> Wouldn't it make sense if some random developer were to run 
> createsuperuser using django settings with any of the databases (as an 
> example) that it prevent them if say that email isn't on say an internal 
> list in the django admin of approved potential users?
>
> I see something like this being a good idea to prevent just anyone from 
> getting full control over the site without it being specifically provided.
>
> Maybe there's something I'm missing something but been reading about third 
> party options and more about what's there and I just feel there's a hole 
> when it comes to who can create a super user account. Obviously you could 
> have a script that you run to initialize who is a super user, what the 
> groups are etc, but then you're basically recording personal information 
> somewhere when that should only be typed in.
>
> Open to ideas and thoughts, mostly just curious what could be a good 
> answer.
>
> Best,
>
> JJ
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d6c2514a-e74f-4946-a1d8-7dbf57937096%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


More controls on createsuperuser

2019-04-28 Thread JJ Zolper
All,

Curious what people think about more thought and control going into who can 
run the createsuperuser method?

For example say there's models that I don't want anyone to touch except 
myself as a superuser. Is it not plausible that even if I make a Django 
Group around that model that someone could still run createsuperuser and 
give themselves the ability to have full control?

Wouldn't it make sense if some random developer were to run createsuperuser 
using django settings with any of the databases (as an example) that it 
prevent them if say that email isn't on say an internal list in the django 
admin of approved potential users?

I see something like this being a good idea to prevent just anyone from 
getting full control over the site without it being specifically provided.

Maybe there's something I'm missing something but been reading about third 
party options and more about what's there and I just feel there's a hole 
when it comes to who can create a super user account. Obviously you could 
have a script that you run to initialize who is a super user, what the 
groups are etc, but then you're basically recording personal information 
somewhere when that should only be typed in.

Open to ideas and thoughts, mostly just curious what could be a good answer.

Best,

JJ

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f8e18aa2-becb-4c06-bc6b-397652332602%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Generate PDF using reportlab and write to s3 bucket without saving locally

2019-04-28 Thread dzulzer
Figured it out: streams have this builtin position attr which bytesIO uses 
to keep track of to know where to insert data. Reportlab simpledoctemplate 
writes to the stream object, but when it completes pdf generation at 
doc.build(story), it doesn't reset the stream position back to the 
beginning of the file. as a result the s3 put_object method writes only the 
portion of the file from where the position is at currently, through to the 
end, resulting in corrupt file. all that was neeeded was to reset the 
stream position just before writing to s3 using stream.seek(0)

On Monday, 22 April 2019 21:18:14 UTC+10, Danny Blaker wrote:
>
> I'm trying to generate a PDF using reportlab and write to s3 bucket 
> without saving locally
>
> I know I'm missing something simple:
>
> # create a stream
> stream = io.BytesIO()
>
> # generate PDF
> doc = SimpleDocTemplate(stream, pagesize=letter,
> rightMargin=72, leftMargin=72,
> topMargin=72, bottomMargin=18)
> Story = []
>
> styles = getSampleStyleSheet()
>
> Story.append(Paragraph('This is a PDF', 
> styles["Normal"]))
>
> doc.build(Story)
>
> # get buffer
> pdf_buffer = stream.getbuffer()
>
> filename = "new.pdf"
> bucket_name = 'insert_bucket_name'
> object_name = bucket_name
>
> # here is where I get stuck - how should be passing the pdf_buffer to s3?
>
> # how you typically write to s3 :
> # Method 1
>
> s3 = boto3.client('s3')
> with open(filename, "rb") as f:
> s3.upload_fileobj(f, bucket_name, object_name)
>
> # Method 2
> s3.Bucket(bucket_name).put_object(Key=filename, Body=file)
>
> Any ideas most appreciated!
>
> Thanks!
>
> here are some related resources:
>
>
> https://stackoverflow.com/questions/43373006/django-reportlab-save-generated-pdf-directly-to-filefield-in-aws-s3
> https://sciwiki.fredhutch.org/compdemos/aws-python/#about-pandas-and-dask
>
> https://stackoverflow.com/questions/12570465/how-to-upload-a-file-to-s3-without-creating-a-temporary-local-file
>
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c7dab075-5edb-41ac-932b-090d8738a7e6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question about form_valid: how to automatically set multiple fields when users input data via CreateView supported form?

2019-04-28 Thread Atsunori Kaneshige
Hi, Britto,

Wow, it's working as expected!
Thank you so much. (*So sorry, one more question below, please find it!*)

Basically, you added blank=True for author field and article field in 
Comment model.
In this way, I don't need to set author/article field in CommentCreateView.

Instead, we have post function to pass around args and kwargs such as pk.
You created form.py and author and article fields will be automatically 
selected via post function.
I checked admin site and comments I made were successfully saved in 
database now!

New views.py

class ArticleCommentCreateView(LoginRequiredMixin, CreateView):
model = Comment
template_name = 'article_comment_new.html'
fields = ('comment',)
# I don't need 'article' field here, because I set blank=True in 
Comment model
login_url = 'login'
success_url = "/"

def post(self, request, *args, **kwargs):
pk = kwargs['pk']
form = CommentForm(request.POST, pk)
if form.is_valid():
new_comment = form.save(commit=False)
new_comment.author = request.user
new_comment.article = Article.objects.get(id=pk)
new_comment.save()
return HttpResponseRedirect('/')

**
By the way, one last thing I wanted to do on top of what we did here is 
that I wanted to display all comments associated with each article.
I have been trying to take data from Comment database, but I am not 
successful about it.

I am able to take out article data by using *object_list.*
*But I cannot do the same thing for comments.*

I still set related_name='comment' in Comment model.
With this related_name, *{% for comment in article.comments %} *worked in 
previous program.
But now, I cannot take out comment data from database.

Sorry many questions and stealing your time.
I really appreciate your advice.

P.S.
I run shell in my terminal by typing python manage.py shell.
I did from article.models import Comment
and I did Comment.objects.all(), then I got all comments printed in my 
terminal.
I read somewhere in Django docs, saying that I can implement this kind of 
query in django program.
But I also read that this is not best practice in Django if I remember 
correctly.

Sorry, I am looking forward to any advice to take out Comment data and 
display them in the template.

Best regards,

Nori

Here is article_list.html
{% extends 'base.html' %}

{% block title %}Articles{% endblock title %}

{% block content %}
 * {% for article in object_list %}*

  
{{ article.title }} 
by {{ article.author }} |
{{ article.date }}
  
  
{{ article.body }}
Edit
Delete
  

  
   * {% for comment in article.comments %} # this one doesn't work now.*
  
{{ comment.author }} 

{{ comment }}
  
{% endfor %}
  


  {% endfor %}
{% endblock content %}



On Sunday, April 28, 2019 at 3:35:23 PM UTC-4, SimpleHumble wrote:
>
> Sorry there was a mistake in previous mail please ignore. 
> form_valid function will not work use post function above it in 
> ArticleCommentCreateView
> Find attached file for reference,
>
>
> Regards
> Britto
>
>
> On Mon, 29 Apr 2019 at 00:54, Britto . > 
> wrote:
>
>> There was few changes made to template, models and view. Find attached 
>> zip file.
>>
>> in ArticleCommentCreateView added a post function to test first also a 
>> supporting forms.py now commented it.
>> form_valid function working fine after added **kwargs parameter.
>>
>> You could always use a requirements file while sharing code files. For 
>> that use   pip freeze > requirements.txt command.
>>
>>
>> Regards
>> Britto
>>
>>
>> On Sun, 28 Apr 2019 at 20:04, Atsunori Kaneshige > > wrote:
>>
>>> Hi Britto,
>>>
>>> Thank you! Let me try that.
>>>
>>> Also, please find the attached file.
>>> This is whole thing I have.
>>> I did not use anything like docker. You might need some installation.
>>> But I guess, after installing django by pipenv install django==2.1.5 in 
>>> the directory and pipenv shell, I hope you can run the program with python 
>>> manage.py runserver.
>>>
>>> I think, you need to create superuser.
>>> Then you will be able to make a comment to any article.
>>> Right now, I don't have link to go to comment form, so you need to type 
>>> url directly.
>>> You will need to post some articles and then you can make comments on 
>>> them.
>>> Please look at urls.py too see what url you need to put to go to comment 
>>> form.
>>>
>>> Sorry for this confusion.
>>> I am still a django beginner, so wish I could know exactly I need to 
>>> tell you for you to run the program.
>>>
>>> Thank you very much for your help.
>>> Please find the zip file.
>>>
>>> Best regards,
>>>
>>> Nori
>>>
>>>
>>> On Sunday, April 28, 2019 at 10:00:00 AM UTC-4, SimpleHumble wrote:

 If you don't want to display article and author in the template. Use 
 custom form design instead of {% 

Re: How to ask questions on Django

2019-04-28 Thread Larry Martell
http://www.catb.org/~esr/faqs/smart-questions.html


On Sun, Apr 28, 2019 at 12:01 PM John Bagiliko <
john.bagil...@aims-senegal.org> wrote:

> Hi all,
>
> I am a passionate Python Developer. I love Django. I have seen most of the
> questions that are posed here and have tried to help. I usually fail to be
> able to help for insufficient information. I think questions asked on this
> group should have much information to help us know where one is coming
> from, where one wants to go and what problem is stopping one from going
> where he wants to go. More importantly, let's know your efforts and where
> you've already looked and didn't succeed so you don't get suggestions about
> what you've tried already and so on.
> I like Stack Overflow for their strict rules. Check how I asked a question
> on Stack Overflow and got answered in less than 30 minutes here
> .
> I also have this tutorial which I think can be a general solution to most
> of of the questions asked here about forms, queries, CRUD activities etc.
> See it here
> 
>
>
> Best,
> John
>
>
> --
> *Regards*
>
> *JOHN BAGILIKO*
> *MSc. Mathematical Sciences (Big Data and Computer Security)*
> *African Institute for Mathematical Sciences (AIMS) | AIMS Senegal*
>
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACwCsY7Ch%2Bo0r%2Bnkq_0i%3DkVrPFNS69-Teyb3to3tJ0NCf3hW2g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to ask questions on Django

2019-04-28 Thread John Bagiliko
Hi all,

I am a passionate Python Developer. I love Django. I have seen most of the
questions that are posed here and have tried to help. I usually fail to be
able to help for insufficient information. I think questions asked on this
group should have much information to help us know where one is coming
from, where one wants to go and what problem is stopping one from going
where he wants to go. More importantly, let's know your efforts and where
you've already looked and didn't succeed so you don't get suggestions about
what you've tried already and so on.
I like Stack Overflow for their strict rules. Check how I asked a question
on Stack Overflow and got answered in less than 30 minutes here
.
I also have this tutorial which I think can be a general solution to most
of of the questions asked here about forms, queries, CRUD activities etc.
See it here



Best,
John

-- 
*Regards*

*JOHN BAGILIKO*
*MSc. Mathematical Sciences (Big Data and Computer Security)*
*African Institute for Mathematical Sciences (AIMS) | AIMS Senegal*

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAC26BE1EwPV-sd1E_otcj1CLXs%2BChp1VDemX2X6%3DMMfYAi%3DqbQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question about form_valid: how to automatically set multiple fields when users input data via CreateView supported form?

2019-04-28 Thread Britto .
If you don't want to display article and author in the template. Use custom
form design instead of {% form.as_p %} tag.

Something like 
this will render only comment field on template. You should not remove
those fields as those are required to process form.

Share the code as zip will exam it and let you know.

On Sun, 28 Apr, 2019, 7:10 PM Atsunori Kaneshige, 
wrote:

> Hi Britto,
>
> Thank you for your reply.
> It's been working fine when I add ('comment', 'article',).
> The fields for CommentCreateView used to be ('comment',
> 'article','author',)
> But I wanted to get rid of 'author' and 'article' from comment form.
>
> def form_valid(self, form):
> form.instance.author = self.request.user
>  return super().form_valid(form)
>
>
> On Sunday, April 28, 2019 at 1:10:24 AM UTC-4, SimpleHumble wrote:
>>
>> set form.instance.article = request.POST.get('article')
>> and add article in fields too like fields = ('comment', 'article')
>> it should work flawlessly.
>>
>>
>> Regards
>> Britto
>>
>>
>> On Sun, 28 Apr 2019 at 09:30, Atsunori Kaneshige 
>> wrote:
>>
>>> Hi, Britto,
>>>
>>> Thank you very much for your reply!
>>> I tried form.instance.article = *self.*request.POST.get('article'), I
>>> still got an error shown below.
>>>
>>>
>>> RelatedObjectDoesNotExist at /articles/2/comment/
>>>
>>> Comment has no article.
>>>
>>> Request Method: POST
>>> Request URL: http://127.0.0.1:8000/articles/2/comment/
>>> Django Version: 2.1.5
>>> Exception Type: RelatedObjectDoesNotExist
>>> Exception Value:
>>>
>>> Comment has no article.
>>>
>>> Exception Location: 
>>> /Users/Koitaro/.local/share/virtualenvs/MMBlog-58h299OP/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py
>>> in __get__, line 188
>>> Python Executable:
>>> /Users/Koitaro/.local/share/virtualenvs/MMBlog-58h299OP/bin/python
>>> Python Version: 3.6.5
>>>
>>>
>>> When I tried print(dir(self.request.POST)), I got the below.
>>>
>>>
>>> ['__class__', '__contains__', '__copy__', '__deepcopy__', '__delattr__',
>>> '__delitem__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__',
>>> '__ge__', '__getattribute__', '__getitem__', '__getstate__', '__gt__',
>>> '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__',
>>> '__len__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__',
>>> '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__setstate__',
>>> '__sizeof__', '__str__', '__subclasshook__', '__weakref__',
>>> '_assert_mutable', '_encoding', '_getlist', '_mutable', 'appendlist',
>>> 'clear', 'copy', 'dict', 'encoding', 'fromkeys', 'get', 'getlist', 'items',
>>> 'keys', 'lists', 'pop', 'popitem', 'setdefault', 'setlist',
>>> 'setlistdefault', 'update', 'urlencode', 'values']
>>>
>>>
>>> When I tried print(self.request.POST.items), I got the blow, for example.
>>>
>>>
>>> >> {'csrfmiddlewaretoken':
>>> ['qRGlWdPTX9qxpFidwKT8bvY3vWXx5caE2wJZSQTtyWodYSICmW4yMwXG3FAn9oQk'],
>>> 'comment': ['I am maru'], 'article': ['2']}>>
>>>
>>>
>>> I typed the message ('I am maru') and needed to specify the article that
>>> I made the message to. I needed to set fields = ('comment','article',) in
>>> CommentCreateView, otherwise, I get an error like the below.
>>>
>>>
>>> RelatedObjectDoesNotExist at /articles/2/comment/
>>>
>>> Comment has no article.
>>>
>>> Request Method: POST
>>> Request URL: http://127.0.0.1:8000/articles/2/comment/
>>> Django Version: 2.1.5
>>> Exception Type: RelatedObjectDoesNotExist
>>> Exception Value:
>>>
>>> Comment has no article.
>>>
>>> Exception Location: 
>>> /Users/Koitaro/.local/share/virtualenvs/MMBlog-58h299OP/lib/python3.6/site-packages/django/db/models/fields/related_descriptors.py
>>> in __get__, line 188
>>> Python Executable:
>>> /Users/Koitaro/.local/share/virtualenvs/MMBlog-58h299OP/bin/python
>>>
>>>
>>> I tried other listed attributes, but seems like I could not find
>>> 'article' information.
>>> When I set the article field and choose an article, I get like
>>> 'article':  ['2'].
>>>
>>> Regarding user, by adding form.instance.author = self.request.user,
>>> 'author' was automatically set without choosing it in the form. But, I did
>>> not see any author information when I tried several 
>>> print(self.request.POST.XXX)
>>> thing.
>>>
>>> When I tried print(self.request.user), the user was printed in terminal.
>>> But, when I tried print(self.request.POST.user), I got an error like
>>> below.
>>>
>>>
>>> AttributeError at /articles/2/comment/
>>>
>>> 'QueryDict' object has no attribute 'user'
>>>
>>> Request Method: POST
>>> Request URL: http://127.0.0.1:8000/articles/2/comment/
>>> Django Version: 2.1.5
>>> Exception Type: AttributeError
>>> Exception Value:
>>>
>>> 'QueryDict' object has no attribute 'user'
>>>
>>>
>>>
>>> When I set the article field, and choose an article in the comment form,
>>> I tried print(form.instance.article). Then, the article I chose was printed
>>> in the terminal.
>>> So, seems like form.instance.article is correct.
>>>
>>> But how 

Specific Blog Post not showing whole post after clicking link

2019-04-28 Thread silverstrings026
I have a personal_blog app that links to a full view of the post the user 
clicked on. I had it working but had to change the code so only the author 
could see it and somehow that ruined the fix. it links fine to the post, 
shows post id in the url (i.e 127.0.0.1:8000/personal_blog/1/ ) but no post 
info. I've run out of research on this, I keep getting the same links and 
alot of them have depricated code. 

Thank you for the help



{% extends 'personal_blog/personal_base.html' %}

{% block content %}
{% for post in posts %}
{{ post.date|date:"Y-m-d" }}{{ post.author }}
{{ post.title }}
{% endfor %}
{% endblock %}
===

{% extends "personal_blog/personal_base.html" %}

{% block content %}

{{ post.title }}
on {{ post.published_date }}
{{ post.text|linebreaks }}

{% endblock %}
=
# personal_blog/models.py
from django.conf import settings
from django.db import models
from django.utils import timezone
from django.utils.http import urlquote
from django.utils.translation import ugettext_lazy as _
from django.core.mail import send_mail
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin
from django.contrib.auth.models import BaseUserManager
from django.contrib.auth import get_user_model
from datetime import datetime
User = get_user_model()
# Create your models here.
class PersonalBlogPost(models.Model): 
objects = models.Manager() # <==Could not call PersonalBlogPost.objects on 
anything unless I did this. 
author = models.ForeignKey(User, related_name='personal_blog_poster', 
on_delete=models.CASCADE, null=True)
title = models.CharField(max_length=200)
text = models.TextField()
created_date = models.DateTimeField(auto_now=True, null=True)#, blank=True) 
published_date = models.DateTimeField(auto_now=True, null=True)#blank=True)
def publish(self):
self.published_date = timezone.now()
self.save()

def __str__(self):
return self.title
===
# public_posts/views.py

from django.shortcuts import render
from django.utils import timezone
from .models import PersonalBlogPost
from django.urls import reverse_lazy
from django.views import generic
from django.http import HttpResponseRedirect, HttpResponseNotFound
from django.shortcuts import render, redirect
from . import forms
from django.forms import ModelForm as Form
from datetime import datetime

def personal_blog_post_list(request):
posts = PersonalBlogPost.objects.filter(published_date__lte=
datetime.now()).order_by('-published_date')
return render(request, 'personal_blog/personal_blog.html', {'posts': posts})

def view_post(request):
posts = PersonalBlogPost.objects.get(pk=request.post_id)
return render(request, 'personal_blog/post.html', {'posts': posts})

def new_personal_post(request):
if request.method == 'POST':
form = forms.PersonalBlogPostForm(request.POST)
if form.is_valid():
personal_post = form.save(commit=False)
personal_post.author = request.user
personal_post.save()
return redirect('blog_personal')
else:
form = forms.PersonalBlogPostForm()
return render(request, 'personal_blog/new_post.html', {'form': form})
===
# personal_blog/urls.py

from django.conf.urls import url, include
from django.urls import path
from django.views.generic import ListView, DetailView, TemplateView
from .models import PersonalBlogPost
from . import views
urlpatterns = [
path('', views.personal_blog_post_list, name='personal_blog'),
url(r'^personal_blog/', views.new_personal_post, name='new_post'), 
url(r'^(?P\w)/$', ListView.as_view(model = PersonalBlogPost,
template_name = 'personal_blog/personal_blog.html')),
url(r'^',views.view_post, name='view_post'),


-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cc02a4e5-920a-49df-baa9-7ec8c25ee3a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: GraphQL and Django integration

2019-04-28 Thread Kaushik Roy
Hi,
Please refer to https://github.com/mirumee/saleor project in github, it has
integration with React, GraphQL, Apollo/Relay and obviously Django.
It is an e-commerce site. you can use it for a reference.
https://demo.getsaleor.com/en/

On Sun, 28 Apr 2019 at 07:02, Britto .  wrote:

> Hi,
>
> What are the coding challenges to integrate GraphQL with Django?
> GraphQL is not like REST it is protocol independent query language.
> How to handle mutations at Django?
>
>
> Regards
> Ab
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAF0v3b40%3Db-2U40JaYObpDZNx%3DLuFti7yr4yYBBptJKSA4LTgg%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
kaushik

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOLM2VMOWJi2oRQ%3DGprhK3s1wGg01B0uF%2BEjJQwZi48FLBOB-g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django URLs

2019-04-28 Thread Anirudh Jain
What is the function 'detail' ? You need to assign 'slug' variable also in
order to pass it to the url.

On Sun, 28 Apr 2019, 13:50 Aayush Bhattarai, 
wrote:

> Hello Everyone,
>
> I want to pass two url in url of template. I have added in urls.py also.
>
> code:-
> Index.html
> *http://detail.id> %}"
> target="_blank">*
> *In Up I want to pass slug. What Should I do.*
>
> *urls.py:*
>
> *path("detail//"),*
>
> *Thanks For Help*
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e9ecfa89-1175-405a-b3d4-f3808b7f2b0f%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAC3mK7fhj3e_LcuLwhm7Eu-qDVBWXeZNuFmqwBu15sdGpMrx-Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to create the django_migrations table (ORA-00907: missing right parenthesis)

2019-04-28 Thread Jani Tiainen
And why you get the error is that Oracle 12 does have new identity column
(generates primary keys without explicit trigger) which was taken into use
in Django. Oracle 11g doesn't have it and thus you get pretty strange
errors when you try to create tables that don't have valid 11g SQL syntax.

On Sun, Apr 28, 2019 at 12:59 PM Jani Tiainen  wrote:

> Hi.
>
> Django 2.2 supports Oracle 12.1+. Oracle 11g support was dropped with
> Django 2.0. If you want to use Oracle 11g (which is out of support anyway
> from Oracle) you either need to downgrade to Django 1.11 and cx_Oracle 6.4.1
>
> I really suggest you to update at least latest Oracle 12.2 which is still
> supported by Oracle.
>
> la 27. huhtik. 2019 klo 22.56 tossouwisdom 
> kirjoitti:
>
>> Django 2.2.2
>> Cx_oracle 7.2
>> base Oracle 11g
>>
>> When I run the django migrate commande, i have error 
>> django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the 
>> django_migrations table (ORA-00907: missing right parenthesis)
>>
>>   Operations to perform:
>>   Apply all migrations: admin, auth, contenttypes, sessions
>> Running migrations:
>> Traceback (most recent call last):
>>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
>> 82, in _execute
>> return self.cursor.execute(sql)
>>   File "C:\Python37-32\lib\site-packages\django\db\backends\oracle\base.py", 
>> line 510, in execute
>> return self.cursor.execute(query, self._param_generator(params))
>> cx_Oracle.DatabaseError: ORA-00907: missing right parenthesis
>>
>> The above exception was the direct cause of the following exception:
>>
>> Traceback (most recent call last):
>>   File "C:\Python37-32\lib\site-packages\django\db\migrations\recorder.py", 
>> line 67, in ensure_schema
>> editor.create_model(self.Migration)
>>   File "C:\Python37-32\lib\site-packages\django\db\backends\base\schema.py", 
>> line 307, in create_model
>> self.execute(sql, params or None)
>>   File "C:\Python37-32\lib\site-packages\django\db\backends\base\schema.py", 
>> line 137, in execute
>> cursor.execute(sql, params)
>>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
>> 99, in execute
>> return super().execute(sql, params)
>>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
>> 67, in execute
>> return self._execute_with_wrappers(sql, params, many=False, 
>> executor=self._execute)
>>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
>> 76, in _execute_with_wrappers
>> return executor(sql, params, many, context)
>>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
>> 84, in _execute
>> return self.cursor.execute(sql, params)
>>   File "C:\Python37-32\lib\site-packages\django\db\utils.py", line 89, in 
>> __exit__
>> raise dj_exc_value.with_traceback(traceback) from exc_value
>>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
>> 82, in _execute
>> return self.cursor.execute(sql)
>>   File "C:\Python37-32\lib\site-packages\django\db\backends\oracle\base.py", 
>> line 510, in execute
>> return self.cursor.execute(query, self._param_generator(params))
>> django.db.utils.DatabaseError: ORA-00907: missing right parenthesis
>>
>> During handling of the above exception, another exception occurred:
>>
>> Traceback (most recent call last):
>>   File "manage.py", line 21, in 
>> main()
>>   File "manage.py", line 17, in main
>> execute_from_command_line(sys.argv)
>>   File 
>> "C:\Python37-32\lib\site-packages\django\core\management\__init__.py", line 
>> 381, in execute_from_command_line
>> utility.execute()
>>   File 
>> "C:\Python37-32\lib\site-packages\django\core\management\__init__.py", line 
>> 375, in execute
>> self.fetch_command(subcommand).run_from_argv(self.argv)
>>   File "C:\Python37-32\lib\site-packages\django\core\management\base.py", 
>> line 323, in run_from_argv
>> self.execute(*args, **cmd_options)
>>   File "C:\Python37-32\lib\site-packages\django\core\management\base.py", 
>> line 364, in execute
>> output = self.handle(*args, **options)
>>   File "C:\Python37-32\lib\site-packages\django\core\management\base.py", 
>> line 83, in wrapped
>> res = handle_func(*args, **kwargs)
>>   File 
>> "C:\Python37-32\lib\site-packages\django\core\management\commands\migrate.py",
>>  line 234, in handle
>> fake_initial=fake_initial,
>>   File "C:\Python37-32\lib\site-packages\django\db\migrations\executor.py", 
>> line 91, in migrate
>> self.recorder.ensure_schema()
>>   File "C:\Python37-32\lib\site-packages\django\db\migrations\recorder.py", 
>> line 69, in ensure_schema
>> raise MigrationSchemaMissing("Unable to create the django_migrations 
>> table (%s)" % exc)
>> django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the 
>> django_migrations table (ORA-00907: missing right parenthesis)
>>
>> --
>> You received this message because 

Re: Unable to create the django_migrations table (ORA-00907: missing right parenthesis)

2019-04-28 Thread Jani Tiainen
Hi.

Django 2.2 supports Oracle 12.1+. Oracle 11g support was dropped with
Django 2.0. If you want to use Oracle 11g (which is out of support anyway
from Oracle) you either need to downgrade to Django 1.11 and cx_Oracle 6.4.1

I really suggest you to update at least latest Oracle 12.2 which is still
supported by Oracle.

la 27. huhtik. 2019 klo 22.56 tossouwisdom 
kirjoitti:

> Django 2.2.2
> Cx_oracle 7.2
> base Oracle 11g
>
> When I run the django migrate commande, i have error 
> django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the 
> django_migrations table (ORA-00907: missing right parenthesis)
>
>   Operations to perform:
>   Apply all migrations: admin, auth, contenttypes, sessions
> Running migrations:
> Traceback (most recent call last):
>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
> 82, in _execute
> return self.cursor.execute(sql)
>   File "C:\Python37-32\lib\site-packages\django\db\backends\oracle\base.py", 
> line 510, in execute
> return self.cursor.execute(query, self._param_generator(params))
> cx_Oracle.DatabaseError: ORA-00907: missing right parenthesis
>
> The above exception was the direct cause of the following exception:
>
> Traceback (most recent call last):
>   File "C:\Python37-32\lib\site-packages\django\db\migrations\recorder.py", 
> line 67, in ensure_schema
> editor.create_model(self.Migration)
>   File "C:\Python37-32\lib\site-packages\django\db\backends\base\schema.py", 
> line 307, in create_model
> self.execute(sql, params or None)
>   File "C:\Python37-32\lib\site-packages\django\db\backends\base\schema.py", 
> line 137, in execute
> cursor.execute(sql, params)
>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
> 99, in execute
> return super().execute(sql, params)
>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
> 67, in execute
> return self._execute_with_wrappers(sql, params, many=False, 
> executor=self._execute)
>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
> 76, in _execute_with_wrappers
> return executor(sql, params, many, context)
>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
> 84, in _execute
> return self.cursor.execute(sql, params)
>   File "C:\Python37-32\lib\site-packages\django\db\utils.py", line 89, in 
> __exit__
> raise dj_exc_value.with_traceback(traceback) from exc_value
>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
> 82, in _execute
> return self.cursor.execute(sql)
>   File "C:\Python37-32\lib\site-packages\django\db\backends\oracle\base.py", 
> line 510, in execute
> return self.cursor.execute(query, self._param_generator(params))
> django.db.utils.DatabaseError: ORA-00907: missing right parenthesis
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
>   File "manage.py", line 21, in 
> main()
>   File "manage.py", line 17, in main
> execute_from_command_line(sys.argv)
>   File "C:\Python37-32\lib\site-packages\django\core\management\__init__.py", 
> line 381, in execute_from_command_line
> utility.execute()
>   File "C:\Python37-32\lib\site-packages\django\core\management\__init__.py", 
> line 375, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "C:\Python37-32\lib\site-packages\django\core\management\base.py", 
> line 323, in run_from_argv
> self.execute(*args, **cmd_options)
>   File "C:\Python37-32\lib\site-packages\django\core\management\base.py", 
> line 364, in execute
> output = self.handle(*args, **options)
>   File "C:\Python37-32\lib\site-packages\django\core\management\base.py", 
> line 83, in wrapped
> res = handle_func(*args, **kwargs)
>   File 
> "C:\Python37-32\lib\site-packages\django\core\management\commands\migrate.py",
>  line 234, in handle
> fake_initial=fake_initial,
>   File "C:\Python37-32\lib\site-packages\django\db\migrations\executor.py", 
> line 91, in migrate
> self.recorder.ensure_schema()
>   File "C:\Python37-32\lib\site-packages\django\db\migrations\recorder.py", 
> line 69, in ensure_schema
> raise MigrationSchemaMissing("Unable to create the django_migrations 
> table (%s)" % exc)
> django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the 
> django_migrations table (ORA-00907: missing right parenthesis)
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> 

Django URLs

2019-04-28 Thread Aayush Bhattarai
Hello Everyone,

I want to pass two url in url of template. I have added in urls.py also.

code:-
Index.html
**
*In Up I want to pass slug. What Should I do.*

*urls.py:*

*path("detail//"),*

*Thanks For Help*

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e9ecfa89-1175-405a-b3d4-f3808b7f2b0f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: GraphQL and Django integration

2019-04-28 Thread Jani Tiainen
Hi,

REST is actually protocol independent. Though most common usage is to use
it through HTTP. Same applies to GraphQL even it's protocol independent
most common usage is still through HTTP.

Now there exists library called graphene and django-graphene for Django
integration.

Challenge is that GraphQL requires much more machinery on the server side
compared to REST (which is rather straightforward).

You could start with
https://stackabuse.com/building-a-graphql-api-with-django/ for example.


On Sun, Apr 28, 2019 at 4:32 AM Britto .  wrote:

> Hi,
>
> What are the coding challenges to integrate GraphQL with Django?
> GraphQL is not like REST it is protocol independent query language.
> How to handle mutations at Django?
>
>
> Regards
> Ab
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAF0v3b40%3Db-2U40JaYObpDZNx%3DLuFti7yr4yYBBptJKSA4LTgg%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Jani Tiainen
Software wizard

https://blog.jani.tiainen.cc/

Always open for short term jobs or contracts to work with Django.

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHn91ofMNg7%3Dh14ck1offnJJBKqFJc7CJfmGLvcFUV3DmESZNA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Question about form_valid: how to automatically set multiple fields when users input data via CreateView supported form?

2019-04-28 Thread chirag soni
Please share the form and form template as well.

On Sun, 28 Apr 2019, 02:37 Atsunori Kaneshige  I really appreciate if anybody could give me an advice about form_valid.
>
> Here is what I want to do.
> I am making a simple blog.
> I am making simple features:
> 1) only superuser can create articles.
> 2) logged-in users can make comments to articles.
>
> I followed along tutorials and mostly done.
> *But last thing I want to do is that when users make comments to any
> articles, I want author field and article field to be automatically set.*
> *Currently, users need to choose author field and article field to make
> comments as well as comment texts.*
>
> The tutorial that I followed along uses form_valid and by using
> form_valid, now I don't need to choose author.
> But I have been struggling with how to automatically set article field by
> using form_valid.
>
> I have a simple models.py and views.py below.
>
> 
>
> class Article(models.Model):
> title = models.CharField(max_length=255)
> body = models.TextField()
> date = models.DateTimeField(auto_now_add=True)
> author = models.ForeignKey(
> get_user_model(),
> on_delete=models.CASCADE,
> )
>
> def __str__(self):
> return self.title
>
> def get_absolute_url(self):
> return reverse('article_detail', args=[str(self.id)])
>
> class Comment(models.Model): # new
> article = models.ForeignKey(
> Article,
> on_delete=models.CASCADE,
> related_name = 'comments',
> )
> comment = models.CharField(max_length=140)
> author = models.ForeignKey(
> get_user_model(),
> on_delete=models.CASCADE,
> )
>
> def __str__(self):
> return self.comment
>
> def get_absolute_url(self):
> return reverse('article_list')
>
> 
> ...(not showing all)
> #for comment
> class ArticleCommentCreateView(LoginRequiredMixin, CreateView):
> model = Comment
> template_name = 'article_comment_new.html'
> fields = ('comment',)
> login_url = 'login'
>
> def form_valid(self, form):
> form.instance.author = self.request.user
> *form.instance.article = self.request.article*
> return super().form_valid(form)
>
> I keep getting errors with this code.
> I know that *form.instance.article = self.request.article* is something
> wrong, but I am having hard time to figure out how to set article field to
> be automatically set.
>
>
> Please give any advice about this.
> I really appreciate.
>
> Looking forward to hearing from anyone.
>
> Best regards,
>
> Nori
>
>
>
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/fe3a8f1d-2e97-41f8-8af4-fe638cb9e787%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABCRpYPSLS1tYJRv23LiQM6LfaFQhvLbinVbXoX2cnnYmaDrcA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to create the django_migrations table (ORA-00907: missing right parenthesis)

2019-04-28 Thread chirag soni
After executive these two commands:

py manage.py makemigrations
py manage.py migrate

Still you face the problem then go to migrations folder and delete the
associated(or all) migrations then re execute the above commands.

On Sun, 28 Apr 2019, 01:26 tossouwisdom  Django 2.2.2
> Cx_oracle 7.2
> base Oracle 11g
>
> When I run the django migrate commande, i have error 
> django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the 
> django_migrations table (ORA-00907: missing right parenthesis)
>
>   Operations to perform:
>   Apply all migrations: admin, auth, contenttypes, sessions
> Running migrations:
> Traceback (most recent call last):
>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
> 82, in _execute
> return self.cursor.execute(sql)
>   File "C:\Python37-32\lib\site-packages\django\db\backends\oracle\base.py", 
> line 510, in execute
> return self.cursor.execute(query, self._param_generator(params))
> cx_Oracle.DatabaseError: ORA-00907: missing right parenthesis
>
> The above exception was the direct cause of the following exception:
>
> Traceback (most recent call last):
>   File "C:\Python37-32\lib\site-packages\django\db\migrations\recorder.py", 
> line 67, in ensure_schema
> editor.create_model(self.Migration)
>   File "C:\Python37-32\lib\site-packages\django\db\backends\base\schema.py", 
> line 307, in create_model
> self.execute(sql, params or None)
>   File "C:\Python37-32\lib\site-packages\django\db\backends\base\schema.py", 
> line 137, in execute
> cursor.execute(sql, params)
>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
> 99, in execute
> return super().execute(sql, params)
>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
> 67, in execute
> return self._execute_with_wrappers(sql, params, many=False, 
> executor=self._execute)
>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
> 76, in _execute_with_wrappers
> return executor(sql, params, many, context)
>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
> 84, in _execute
> return self.cursor.execute(sql, params)
>   File "C:\Python37-32\lib\site-packages\django\db\utils.py", line 89, in 
> __exit__
> raise dj_exc_value.with_traceback(traceback) from exc_value
>   File "C:\Python37-32\lib\site-packages\django\db\backends\utils.py", line 
> 82, in _execute
> return self.cursor.execute(sql)
>   File "C:\Python37-32\lib\site-packages\django\db\backends\oracle\base.py", 
> line 510, in execute
> return self.cursor.execute(query, self._param_generator(params))
> django.db.utils.DatabaseError: ORA-00907: missing right parenthesis
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
>   File "manage.py", line 21, in 
> main()
>   File "manage.py", line 17, in main
> execute_from_command_line(sys.argv)
>   File "C:\Python37-32\lib\site-packages\django\core\management\__init__.py", 
> line 381, in execute_from_command_line
> utility.execute()
>   File "C:\Python37-32\lib\site-packages\django\core\management\__init__.py", 
> line 375, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "C:\Python37-32\lib\site-packages\django\core\management\base.py", 
> line 323, in run_from_argv
> self.execute(*args, **cmd_options)
>   File "C:\Python37-32\lib\site-packages\django\core\management\base.py", 
> line 364, in execute
> output = self.handle(*args, **options)
>   File "C:\Python37-32\lib\site-packages\django\core\management\base.py", 
> line 83, in wrapped
> res = handle_func(*args, **kwargs)
>   File 
> "C:\Python37-32\lib\site-packages\django\core\management\commands\migrate.py",
>  line 234, in handle
> fake_initial=fake_initial,
>   File "C:\Python37-32\lib\site-packages\django\db\migrations\executor.py", 
> line 91, in migrate
> self.recorder.ensure_schema()
>   File "C:\Python37-32\lib\site-packages\django\db\migrations\recorder.py", 
> line 69, in ensure_schema
> raise MigrationSchemaMissing("Unable to create the django_migrations 
> table (%s)" % exc)
> django.db.migrations.exceptions.MigrationSchemaMissing: Unable to create the 
> django_migrations table (ORA-00907: missing right parenthesis)
>
> --
> 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 post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/dac2cda6-2543-4664-aea5-025473ecc3e5%40googlegroups.com
>