Re: How to increase file upload size in twitter in django rest api

2019-10-10 Thread Cornelis Poppema
Are you perhaps looking for 
https://docs.djangoproject.com/en/2.2/ref/settings/#data-upload-max-memory-size
 ?

On Thursday, 10 October 2019 07:04:31 UTC+2, ajitkumar wrote:
>
> Hi, 
>
> can anyone help me how to increase media upload size in django rest api, 
>
>
>
>
> Thanks in advance. 
>
>
>

-- 
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/a087ef9d-0fe5-4565-9597-2bd536030511%40googlegroups.com.


Re: list cycle in template

2019-10-09 Thread Cornelis Poppema
{{ mylist.a }} means: get attribute "a" from object "mylist". For the 
template it doesn't matter if you have defind a variable "a", it will get 
the literal "a". Also see 
https://stackoverflow.com/questions/4651172/reference-list-item-by-index-withdoesin-django-template
 

 for 
others with the same problem and a solution. You can add a template filter 
which *does* support variables. Your template will then look like {{ 
mylist|index:a }}. Credits to Bakuutin 
 and WeizhongTu 
 for this specific 
example:

from django import template
register = template.Library()
@register.filterdef index(indexable, i):
return indexable[i]


{% load index %}{{ mylist|index:a }}


I believe you will need to do the same if you want to access any property 
from that item, ie. {{ mylist|index:a }}.property doesn't work, you would 
need to write a new filter to be able to do {{ 
mylist|index:a|attr:"property" }}

Besides all this, is there a reason you cannot simply use a for-loop to 
iterate over mylist ?

{% for item in mylist %}

{{ item.property }}

{% endfor %}



On Wednesday, 9 October 2019 10:16:18 UTC+2, Luca Bertolotti wrote:
>
> Hello in the view a hve a list
> mylist = ['aa','bb']
> n = range(len(mylist))
>
> return render({'mylist':mylist,'n':n,.})
>
> in the template i do this:
>
> {% for a in n %} {{ mylist.a }}
>
> it never show nothing, but if i do:
>
> {% for a in n %} {{ mylist.0 }}
> it show 'aa'
>
> Where is the mistake?
>
> 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/2a47b2ff-5fc6-4c1d-91f1-79549d217ff0%40googlegroups.com.


Re: regarding adding data into database using faker library

2019-09-26 Thread Cornelis Poppema
It seems you have an unfortunate typo in your environment variable name.

Change DJANGO_SETTING_MODULE -> DJANGO_SETTINGS_MODULE and try again.

On Thursday, 26 September 2019 16:26:18 UTC+2, Sahil Sharma wrote:
>
> [image: 2019-09-26-1569507899_screenshot_1920x1080.jpg]
> I did the changes but it not working. I am sharing the screenshot of the 
> program 
> On Wednesday, 25 September 2019 16:34:10 UTC+5:30, Sahil Sharma wrote:
>>
>> So I was adding data into the user model that is create using faker 
>> library  but i am facing certain error 
>>
>>  my populatescript screenshot is inserted
>>
>> [image: 2019-09-24-1569346732_screenshot_1920x1080.jpg]
>>   
>> here is my user model class
>>
>> from django.db import models
>>
>> # Create your models here.
>>
>> class user(models.Model):
>> firstname=models.CharField(max_length=250,unique=False)
>> lastname=models.CharField(max_length=250,unique=False)
>> emailid=models.CharField(max_length=500,unique=True)
>> def __str__(self):
>>
>> return self.emailid
>>
>>
>>
>>
>>
>>

-- 
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/f7a44d30-963d-4b6a-ba02-8cdf2c74d7a8%40googlegroups.com.


Re: regarding adding data into database using faker library

2019-09-26 Thread Cornelis Poppema
The location of your first django.setup() on line 4 was actually what you 
need. Right now it does show the same error but from a different line: the 
line where you import your model.

- you need to do django.setup() before importing any of your project code
- you need to set DJANGO_SETTINGS_MODULE before calilng django.setup()

so your file should like this:

#!/usr/bin/env python
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'firstproject.setting')


import django
django.setup()


import random


from faker import Faker


from firstapp.models import user


def populate(N):
...




if __name__ == '__main__':
populate(10)




On Thursday, 26 September 2019 14:23:33 UTC+2, Sahil Sharma wrote:
>
> [image: 2019-09-26-1569500258_screenshot_1920x1080.jpg]
> After fixing the error of django.setup() I ran the file but it is not 
> working and also showing the error. I am sharing the screenshot of the 
> program along with the error it is showing
>
> On Wednesday, 25 September 2019 16:34:10 UTC+5:30, Sahil Sharma wrote:
>>
>> So I was adding data into the user model that is create using faker 
>> library  but i am facing certain error 
>>
>>  my populatescript screenshot is inserted
>>
>> [image: 2019-09-24-1569346732_screenshot_1920x1080.jpg]
>>   
>> here is my user model class
>>
>> from django.db import models
>>
>> # Create your models here.
>>
>> class user(models.Model):
>> firstname=models.CharField(max_length=250,unique=False)
>> lastname=models.CharField(max_length=250,unique=False)
>> emailid=models.CharField(max_length=500,unique=True)
>> def __str__(self):
>>
>> return self.emailid
>>
>>
>>
>>
>>
>>

-- 
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/8533633e-a4ef-40a7-bfc3-4a56f0aeaf3f%40googlegroups.com.


Re: regarding adding data into database using faker library

2019-09-25 Thread Cornelis Poppema
You almost had it! You're already setting DJANGO_SETTINGS_MODULE before you 
call django.setup() inside your main function. However, you also call 
django.setup() on line 4. You need to set DJANGO_SETTINGS_MODULE before the 
first django.setup().

On Wednesday, 25 September 2019 13:04:10 UTC+2, Sahil Sharma wrote:
>
> So I was adding data into the user model that is create using faker 
> library  but i am facing certain error 
>
>  my populatescript screenshot is inserted
>
> [image: 2019-09-24-1569346732_screenshot_1920x1080.jpg]
>   
> here is my user model class
>
> from django.db import models
>
> # Create your models here.
>
> class user(models.Model):
> firstname=models.CharField(max_length=250,unique=False)
> lastname=models.CharField(max_length=250,unique=False)
> emailid=models.CharField(max_length=500,unique=True)
> def __str__(self):
>
> return self.emailid
>
>
>
>
>
>

-- 
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/3ec98288-706a-4038-8e24-3dba76e83c67%40googlegroups.com.


Re: how to use sql select query with pyodbc and django ?

2019-09-18 Thread Cornelis Poppema
I am not using pyodbc, but I imagine you should %s instead of ? as 
parameter marker. mysql-python actually uses python interpolation to build 
the query instead of simply replacing the ? signs, so pyodbc might do the 
same. If that's the case, it makes sense the error says there are 0 
parameter markers. For reference, check the example from the docs: 
https://docs.djangoproject.com/en/2.2/topics/db/sql/#passing-parameters-into-raw

>>> lname = 'Doe'>>> Person.objects.raw('SELECT * FROM myapp_person WHERE 
>>> last_name = %s', [lname])



On Wednesday, 18 September 2019 08:36:59 UTC+2, leb dev wrote:
>
> i have a django code that connect to sql server database and i am trying 
> to select values using *like *but once i try it it crash and the system 
> display the below error:
>
> ('The SQL contains 0 parameter markers, but 1 parameters were supplied', 
> 'HY000')
>
>
> views.py
>
> 
>
>
> from django.shortcuts import render
> import pyodbc
> # from .models import Artist
> # Create your views here.
>
>
> def connect(request):
>  
> conn = pyodbc.connect(
> 'Driver={ODBC Driver 17 for SQL Server};'
> 'Server=DESKTOP-LPD1575\\SQLEXPRESS;'
> 'Database=testDB;'
> 'UID=test;'
> 'PWD=*;'
>
> )
> query = 'jhon'
> cursor = conn.cursor()
>  
> c = cursor.execute('SELECT * FROM Artist where artistName like 
> "%?%"',query)
> print(c)
> return render (request,'connect.html',{"c":c})
>
>
>
> connect.html
> ==
> 
> 
> id
> FolderNumber
> Folderdate
>
> 
> {% for row in c %}
>  
> {{ row.0 }}
> {{ row.1 }}
> {{ row.2 }}
> 
> 
> {% endfor %}
> 
>
>

-- 
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/7c6435ab-0a86-4b4e-9af2-093d713c0502%40googlegroups.com.


Re: Django's str(queryset.query) returns invalid SQL if I compare datetimes

2019-08-22 Thread Cornelis Poppema
What makes sense to me is the query builder (ORM) in Django 
"escapes"/quotes the values at the very last moment: whenever the query is 
to be executed in a database. Different databases can have different escape 
characters. When you print queryset.query it simply isn't at a stage where 
the escape characters have been added. No "default" quoting is happening 
because Django has no implementation for this: all escaping is off-loaded 
to the specific database packages if possible (e.g. MySQLdb, psycopg2, 
sqlite3). Simply put: queryset.query isn't meant to output valid sql as-is, 
nobody claims as much. In fact, checking the source code actually 
underlines my point:

https://github.com/django/django/blob/8a281aa7fe76a9da2284f943964a9413697cff1f/django/db/models/sql/query.py#L253-L262

def __str__(self):
"""
Return the query as a string of SQL with the parameter values
substituted in (use sql_with_params() to see the unsubstituted string).
Parameter values won't necessarily be quoted correctly, since that is
done by the database interface at execution time.
"""
sql, params = self.sql_with_params()
return sql % params


On Tuesday, 20 August 2019 17:43:38 UTC+2, Jo wrote:
>
> I have a Django queryset that I prepare with 
>
> queryset.filter(date__gte=datetime(2011,1,1))
>
>
> If I then call `str(queryset.query)` I see this in the string:
>
> ... WHERE "App_table"."date" >= 2011-1-1
>
> However, this is invalid SQL code as if I run this in Postgresql I get 
> this error:
>
> ... WHERE "App_table"."date" >= 2011-1-1
> ERROR:  operator does not exist: date >= integer
> HINT:  No operator matches the given name and argument type(s). You 
> might need to add explicit type casts.
>
>
> Why is this happening and how can I ask Django to output proper SQL code 
> that I can work on?
> 
>

-- 
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/0ed2b0cf-f1e1-4bd7-8504-2c99e778c27a%40googlegroups.com.


Re: Accessing data from a 30 GB file in json format

2019-07-01 Thread Cornelis Poppema
To be able to traverse the JSON structure you'd normally need the entire 
structure in memory. For this reason you can't (easily) apply suggestions 
to iterate over a file efficiently to a JSON file: you can perhaps read the 
file efficiently, but the structure in memory will still grow in memory. 
I've found these packages made for efficiently reason large JSON files 
after a quick search: https://github.com/ICRAR/ijson or 
https://github.com/kashifrazzaqui/json-streamer. 
https://stackoverflow.com/a/17326199/248891 shows a simple example when 
using ijson



On Monday, 1 July 2019 12:07:39 UTC+2, Nibil Ashraf wrote:
>
> Hey,
>
> I have a file with a size of around 30GB. The file is in json format. I 
> have to access the data and write that to a csv file. When I tried to do 
> that with my laptop which has a a RAM of 4GB, I am getting some error. I 
> tried to load the json file like this json_parsed = json.loads(json_data)
>
> Can someone help me with this? How should I do this? If I should go with 
> some server, please let me know what specifications should I use? 
>

-- 
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/00dd3f6a-85da-4942-97bb-eae2652cfe96%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Possible bug in python manage.py migrate when changing the field type of a foreign key with a constraint

2019-06-11 Thread Cornelis Poppema
I have two models and a ForeignKey. In this project I'm still using django 
1.11 (still busy migrating to python3) but I have reproduced this in django 
2.2.2

Models are Call and Client. Call has a ForeignKey to a PositiveIntegerField 
on Client. I'm changing the type of this field to a CharField, but 
django/mysql cannot drop or add constraints.

I found this issue: https://code.djangoproject.com/ticket/28305. I had 
hoped I was still using a version of 1.11 that didn't include the backport 
but unfortunately for me I did.
Before creating this post I also came across 
https://code.djangoproject.com/ticket/30152 which is also related to my 
initial findings. As https://code.djangoproject.com/ticket/30152#comment:10 
says, 
the internals of django checking for relations that might have constraints 
but in 30152 and my case it doesn't find the relation. As a result the 
foreign key constraint isn't dropped resulting in the error:

django.db.utils.OperationalError: (1833, "Cannot change column 'code': used 
in a foreign key constraint 
'myapp_call_clientcode_907d4acf_fk_myapp_client_code' of table 
'test_test.myapp_call'")


After either applying the 
patch 
https://code.djangoproject.com/attachment/ticket/30152/testcase_and_rough_fix.patch
 
or simply (temporarily) removing related_name='+' I get past this 
OperationError. Instead I am confronted with:

django.db.utils.IntegrityError: (1215, 'Cannot add foreign key constraint')


>From what I've read about MySQL constraints this is caused by the different 
field types. Changing the type of the original field doesn't change the 
type of the foreign key field and the constraint cannot be re-added after 
dropping it.

I created a project on github: 
https://github.com/cpoppema/django-migrate-constraint-bug, ignore the 
master-branch for now.

Branch with original issue: 
https://github.com/cpoppema/django-migrate-constraint-bug/tree/cannot-change-column-used-in-a-foreign-key-constraint
Branch with issue without related_name='+': 
https://github.com/cpoppema/django-migrate-constraint-bug/tree/cannot-add-foreign-key-constraint

Known workaround that I've come up with is:

run a migration to change ForeignKey on Call to PositiveIntegerField
run a migration to change the PositiveIntegerField on Client to CharField
run a migration to change the PositiveIntegerField on Call to ForeignKey

With this, both fields end up as a CharField. I'd rather have Django 
generate either multiple migrations or do an ALTER TABLE for related fields.

-- 
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/7d778d84-4251-4871-b271-2544fbf0ed08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.