Re: Aide

2019-07-05 Thread PASCUAL Eric
Google est ton ami : "django mongodb" fournit un tas de réponses à cette 
question, y compris des références à des packages d'extension de Django.

Eric


From: django-users@googlegroups.com  on behalf 
of Djamiyou CHITOU 
Sent: Thursday, July 4, 2019 11:48
To: Django users
Subject: Aide

Salut tous svp! j'aimerais associé mongoDB a django que faire?


--
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/264124aa-b58d-4e1e-8aee-3a7535b08fec%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/AM5P193MB0243AF3B6885497CC70391248CF50%40AM5P193MB0243.EURP193.PROD.OUTLOOK.COM.
For more options, visit https://groups.google.com/d/optout.


Re: Aide

2019-07-05 Thread Arnaud Tsombeng
HI Djamiyou,
you can find a solution to you question on django documentation.
Regards

Le ven. 5 juil. 2019 à 00:50, Djamiyou CHITOU  a
écrit :

> Salut tous svp! j'aimerais associé mongoDB a django que faire?
>
> --
> 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/264124aa-b58d-4e1e-8aee-3a7535b08fec%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Arnaud Tsombeng
Python Backend Developer at LeapTure LLC
Tell/whatsapp: +(237)679218852
skype: nkeumo.arnaud
github: Nkarnaud
twitter:@*ArnaudTsombeng* 

-- 
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/CAAgkfwwC2DtD3hnstTGDmNi_2X3qcH%3DCbvz%2Bi7pq6RsuFVOV-w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


help

2019-07-05 Thread Manjunatha Sai Uppu
I am new to web development  in django , i have some questions that
1. Is it necessary to  learn html,css?
2. what are the advantages and disadvantages of django?
3. how it is useful?
4. any best resources that u can provide for me?
 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 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/af9761b8-a365-4b0f-8450-46450ffd70bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django 2.2 Media files

2019-07-05 Thread Michał Ratajczak
Hi, i'm new in Django, I'm trying to configure media files correctly.

That's in my model.py:

class Question(models.Model):
description = models.CharField(max_length=200)
image = models.ImageField(upload_to='media/', null=True, blank=True)


in settings.py:

STATIC_URL = '/static/'
MEDIA_URL = '/media/'

ENV_PATH = os.path.abspath(os.path.dirname(__file__))
STATIC_ROOT = os.path.join(ENV_PATH, '../public/static/') 
MEDIA_ROOT = os.path.join(ENV_PATH, '../public/media/')

in urls.py:

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('barber.urls'))
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

in view.py:
def index(request):
images = Question.objects.values('image')
template = loader.get_template('barber/index.html')
context = {
'images': images
}
return HttpResponse(template.render(context, request))

I'am adding an image via admin site and next i render in template. Url for 
image is "media/image.png" bit file is in .../media/media/image.png, so i 
can't understand it. Can anyone help me ?

-- 
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/5613b376-575f-4ab0-bdff-368f0fe8f1cf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: need help - following django tutorial to create polls database - missing "on delete cascade" - using django 2.2.1 with mysql 8.0

2019-07-05 Thread sachin thakur
I am also facing the same problem i am using PostgreSQL data  base . please
do share this issue bug

*Thanks and Kind Regards*


*Sachin Thakur*
about.me/sachin.thakur

 *PG Student*
Dept. of Computer Applications,
*Christ ( Deemed to Be university) Main Campus Bangalore, India*
*UG (DSCASC under Bangalore University )* Bangalore, India.
Mob: *+91 8792560572*
*E-mail : sachin.thakur9...@gmail.com *
*E-mail : sachin.tha...@mca.christuniversity.in
*




On Sat, Jun 29, 2019 at 3:38 AM Joe Reitman  wrote:

> The notes say:
>
>- The exact output will vary depending on the database you are using.
>The example above is generated for* PostgreSQL.*
>
> Are you using the default SQLite?
>
> You could try running migrate and then checking the tables to see if the
> constraint was added using a DB admin viewer.
>
> For SQLite I use - https://sqlitebrowser.org/
> For Postgres  - https://www.pgadmin.org/
>
>
>
> On Tuesday, May 28, 2019 at 7:44:44 PM UTC-5, K Tan wrote:
>>
>> Hi, everyone,
>>
>> This is my first time using Django and I think I'm missing something or
>> there is a bug. I am following the instructions on (
>> https://docs.djangoproject.com/en/2.2/intro/tutorial02/) and I've just
>> added the following chunk of code to "polls/models.py". (I copied/pasted so
>> I know it's correct.)
>>
>> 
>> from django.db import models
>>
>>
>> class Question(models.Model):
>> question_text = models.CharField(max_length=200)
>> pub_date = models.DateTimeField('date published')
>>
>>
>> class Choice(models.Model):
>> question = models.ForeignKey(Question, on_delete=models.CASCADE)
>> choice_text = models.CharField(max_length=200)
>> votes = models.IntegerField(default=0)
>> 
>>
>>
>> Then I ran the following command:
>>
>> 
>> LITTLEBLACK:www samktan$ python3 manage.py makemigrations polls
>> Migrations for 'polls':
>>   polls/migrations/0001_initial.py
>> - Create model Question
>> - Create model Choice
>> 
>>
>> Which is missing one line compared to the tutorial:
>>
>> - Add field question to choice
>>
>>
>>
>> Now when I run this command:
>>
>> 
>> LITTLEBLACK:www samktan$ python3 manage.py sqlmigrate polls 0001
>> BEGIN;
>> --
>> -- Create model Question
>> --
>> CREATE TABLE `polls_question` (`id` integer AUTO_INCREMENT NOT NULL
>> PRIMARY KEY, `question_text` varchar(200) NOT NULL, `pub_date` datetime(6)
>> NOT NULL);
>> --
>> -- Create model Choice
>> --
>> CREATE TABLE `polls_choice` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY
>> KEY, `choice_text` varchar(200) NOT NULL, `votes` integer NOT NULL,
>> `question_id` integer NOT NULL);
>> ALTER TABLE `polls_choice` ADD CONSTRAINT
>> `polls_choice_question_id_c5b4b260_fk_polls_question_id` FOREIGN KEY
>> (`question_id`) REFERENCES `polls_question` (`id`);
>> COMMIT;
>> 
>>
>> It is missing the "on delete cascade" clause, which I suspect it caused
>> by the missing line above.
>>
>> I have confirmed in MySQL that the "on delete cascade" clause is
>> definitely missing.
>>
>> 
>> mysql> show create table `polls_choice`;
>>
>> +--+-+
>> | Table| Create Table
>>
>>
>>
>>
>>
>>|
>>
>> +--+-+
>> | polls_choice | CREATE TABLE `polls_choice` (
>>   `id` int(11) NOT NULL AUTO_INCREMENT,
>>   `choice_text` varchar(200) COLLATE utf8mb4_general_ci NOT NULL,
>>   `votes` int(11) NOT NULL,
>>   `question_id` int(11) NOT NULL,
>>   PRIMARY KEY (`id`),
>>   KEY `polls_choice_question_id_c5b4b260_fk_polls_question_id`
>> (`question_id`),
>>   CONSTRAINT `polls_choice_question_id_c5b4b260_fk_polls_question_id`
>> FOREIGN KEY (`question_id`) REFERENCES `polls_question` (`id`)
>> ) ENGINE=InnoDB DEFA

Re: help

2019-07-05 Thread Jani Tiainen
Hi.

Please don't hijack other people threads but start a new one.


pe 5. heinäk. 2019 klo 15.55 Manjunatha Sai Uppu 
kirjoitti:

> I am new to web development  in django , i have some questions that
> 1. Is it necessary to  learn html,css?
>

No. Absolutely no. You can write plain backend code for example by using
JSON respondses.

Though if you want to write full web sites HTML and CSS greatly helps.

2. what are the advantages and disadvantages of django?
>

A good friendly community. And it's written in Python. Best programming
language ever.

3. how it is useful?
>

In my opionion it's very fast tool to make ideas to real dynamic web apps.

Also there are tons of Python libraries that you can leverage plus huge
amount apps (kind of plugins) you can use in you Django projects to help
making things even faster.

4. any best resources that u can provide for me?
>

Do tutorials. Django Girls do provide excellent tutorial to get started.

 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 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/af9761b8-a365-4b0f-8450-46450ffd70bf%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/CAHn91of%2BdGkXmq-ut7kxwJyRCL_4m0p_HPVEwEDcf-8XYnb8-Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 2.2 Media files

2019-07-05 Thread John Bagiliko
Remove the upload_to in the model.

On Fri, Jul 5, 2019, 12:55 PM Michał Ratajczak 
wrote:

> Hi, i'm new in Django, I'm trying to configure media files correctly.
>
> That's in my model.py:
>
> class Question(models.Model):
> description = models.CharField(max_length=200)
> image = models.ImageField(upload_to='media/', null=True, blank=True)
>
>
> in settings.py:
>
> STATIC_URL = '/static/'
> MEDIA_URL = '/media/'
>
> ENV_PATH = os.path.abspath(os.path.dirname(__file__))
> STATIC_ROOT = os.path.join(ENV_PATH, '../public/static/')
> MEDIA_ROOT = os.path.join(ENV_PATH, '../public/media/')
>
> in urls.py:
>
> urlpatterns = [
> path('admin/', admin.site.urls),
> path('', include('barber.urls'))
> ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
>
> in view.py:
> def index(request):
> images = Question.objects.values('image')
> template = loader.get_template('barber/index.html')
> context = {
> 'images': images
> }
> return HttpResponse(template.render(context, request))
>
> I'am adding an image via admin site and next i render in template. Url for
> image is "media/image.png" bit file is in .../media/media/image.png, so i
> can't understand it. Can anyone help me ?
>
> --
> 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/5613b376-575f-4ab0-bdff-368f0fe8f1cf%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/CAC26BE3pcXFhzuzWaUhE%3D8z_KGj1UeXKnJOqWQsRrXH-_7eo4g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 2.2 Media files

2019-07-05 Thread John Bagiliko
Since you already configured static folder called media in settings.py, if
you specifify upload_to='/media', Django will create a folder 'media'
inside the media folder.

On Fri, Jul 5, 2019, 2:21 PM John Bagiliko 
wrote:

> Remove the upload_to in the model.
>
> On Fri, Jul 5, 2019, 12:55 PM Michał Ratajczak 
> wrote:
>
>> Hi, i'm new in Django, I'm trying to configure media files correctly.
>>
>> That's in my model.py:
>>
>> class Question(models.Model):
>> description = models.CharField(max_length=200)
>> image = models.ImageField(upload_to='media/', null=True, blank=True)
>>
>>
>> in settings.py:
>>
>> STATIC_URL = '/static/'
>> MEDIA_URL = '/media/'
>>
>> ENV_PATH = os.path.abspath(os.path.dirname(__file__))
>> STATIC_ROOT = os.path.join(ENV_PATH, '../public/static/')
>> MEDIA_ROOT = os.path.join(ENV_PATH, '../public/media/')
>>
>> in urls.py:
>>
>> urlpatterns = [
>> path('admin/', admin.site.urls),
>> path('', include('barber.urls'))
>> ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
>>
>> in view.py:
>> def index(request):
>> images = Question.objects.values('image')
>> template = loader.get_template('barber/index.html')
>> context = {
>> 'images': images
>> }
>> return HttpResponse(template.render(context, request))
>>
>> I'am adding an image via admin site and next i render in template. Url
>> for image is "media/image.png" bit file is in .../media/media/image.png, so
>> i can't understand it. Can anyone help me ?
>>
>> --
>> 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/5613b376-575f-4ab0-bdff-368f0fe8f1cf%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/CAC26BE1jsSya48W0dUgag8XW0eDLjbBjpZW8Ap97mRhq8geNgA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Connecting to SQL Server

2019-07-05 Thread Joe Reitman
When does this error occur? During runserver or when executing a commit 
from your model?

On Thursday, July 4, 2019 at 11:48:40 AM UTC-5, John Burke wrote:
>
> For this particular instance, I don't need the port number.
>
> On Thu, Jul 4, 2019 at 11:47 AM Joe Reitman  > wrote:
>
>> Don't you need to assign a port number?
>>
>> On Wednesday, July 3, 2019 at 6:52:35 PM UTC-5, John Burke wrote:
>>>
>>> Trying to connect to SQL Server from Django
>>>
>>> DATABASES = {
>>> 'default': {
>>> 'ENGINE': 'sql_server.pyodbc',
>>> 'NAME': 'dbname',
>>> 'HOST': 'hostname',
>>> 'PORT': '',
>>> 'USER': 'user',
>>> 'PASSWORD': 'password',
>>> 'OPTIONS': {
>>> 'driver': 'ODBC Driver 13 for SQL Server',
>>> },
>>> }
>>> }
>>>
>>>
>>> I get the following error:
>>> File "...\venv\lib\site-packages\sql_server\pyodbc\base.py", line 362, 
>>> in init_connection_state
>>> val = cursor.execute('SELECT SYSDATETIME()').fetchone()[0]
>>> ValueError: hour must be in 0..23
>>>
>>>
>>> -- 
>> 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 post to this group, send email to django...@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/60dae4de-82b0-472c-987d-9fab48c37f0f%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> -- 
> Regards,
> John B
>

-- 
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/b9b209fc-5795-44b3-ab65-8ea8b10563f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to convert files from .bin to .png with Python or Django

2019-07-05 Thread Fernando Garrido Villalobos
Aldian F.   The .bin files have content  of data in binary format that was 
copied from a disk to this output file

El miércoles, 3 de julio de 2019, 18:52:35 (UTC-5), Fernando Garrido 
Villalobos escribió:
>
> How to create a function that have like argument the path of a .bin file 
> and returns a .png file ...
> I need your help, 
> thank you so much.
>

-- 
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/bc70ca38-f68c-4714-babd-b9db412b91a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: access league by league-code REST api

2019-07-05 Thread omar ahmed
please explain ?

On Friday, July 5, 2019 at 7:25:08 AM UTC+2, Serdar Emirci wrote:
>
>
>  /League > /League
>  
>  
> Serdar EMIRCI
>
>
> omar ahmed >, 5 Tem 2019 Cum, 00:43 
> tarihinde şunu yazdı:
>
>> hiii ..
>> i use REST api to get data from "https://www.football-data.org"; ..
>> i want to create one view that can restore any league (by league code 
>> like: PL for premier league) not for particular league
>> openleague.html
>> {% block content %}
>> 
>> Premier League
>> Spanish League
>> Italian League
>> German League
>> French League
>> 
>> {% endblock %}
>> urls.py
>> urlpatterns =[
>> path('', views.home,name='home'),
>> path('/League', views.openleague, name='openleague'),
>> ]
>> views.py
>> def openleague(request,code):
>> connection = http.client.HTTPConnection('api.football-data.org')
>> headers = { 'X-Auth-Token': '##' }
>> connection.request('GET', '/v2/competitions/{'code'}', None, headers)
>> response = json.loads(connection.getresponse().read().decode())
>>
>> return render(request, 'core/openleague.html', {'response': response})
>>
>> -- 
>> 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 post to this group, send email to django...@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/88b03928-dbbb-4b66-8661-499bdade3381%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/23ccee4d-a0a3-4ede-9036-5cf74bafc4b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


saving inherited model overwrites base model

2019-07-05 Thread Kalev Takkis
Hi all,

tl;dr: saving inherited model overwrites fields in parent models with empty 
strings

I have the following models:

class Contact(models.Model):
comment = models.CharField(max_length=255, blank=True)
emails = models.ManyToManyField(
Email,
blank=True,
through='ContactEmail',
through_fields=('contact', 'email'),
)

# couple of more manytomanys, to addresses, phones, etc


class ContactEmail(BaseContactJunctionModel):
email = models.ForeignKey(Email, null=True, on_delete=models.SET_NULL)
contact = models.ForeignKey(Contact, on_delete=models.CASCADE)
event = models.ForeignKey(ContactEvent, on_delete=models.PROTECT)
event_date = models.DateTimeField(default=timezone.now)


# other similar through tables for the rest of the manytomanys and their 
target models


class Organisation(Contact):

name = models.CharField(max_length=255, blank=True)
hierarchy = models.ManyToManyField(
'self',
blank=True,
symmetrical=False,
through='OrganisationHierarchy',
through_fields=('sender', 'target'),
)

# again, more manytomanys, not to self though

# not sure this is relevant but as it's to self, then just in case
class OrganisationHierarchy(BaseContactJunctionModel):
# this, instance that specifies relationship
sender = models.ForeignKey(
Organisation,
null=True, 
related_name='senders',
on_delete=models.SET_NULL,
)

# instance that 'this' or 'sender' is related to
target = models.ForeignKey(
Organisation,
null=True, 
related_name='targets',
on_delete=models.SET_NULL,
)

connection_type = models.ForeignKey(
ConnectionType,
null=True,
on_delete=models.PROTECT,
)

I have a view based on CreateView and a template to capture user
input. The post request coming from browser is a-ok, saving
emails, contact, contactemails and other manytomany targets and
junction tables works without a problem but when getting to
saving Organisation, this happens (pseudocode):

save() is called from django/db/models/base.py
save_base() is called with self=Organisation
save_base calls _save_parents(self=Organisation, cls=Organisation)
save_parents loops through cls._meta.parents and comes across 
relation
parent=Contact, field=Organisation.contact_ptr
calls _save_table with self=Organisation and cls=Contact
_save_table finds from cls._meta that it has
local concrete field "comment" and stores it in list 
non_pks
it then finds the values for those fields like 
this: 
f.pre_save(self, false) for f in non_pks 

I then see a call to _update in queries.py and Contact instance
is updated with new values.

I don't really understand what's happening here, the code finds
local concrete fields from "cls" which at this point is Contact
and comes up, correctly, with "comment" but then it tries to
query the field value form "self" which at this point is
Organisation object. I'm not sure why Organisation has "comment"
attribute at all, because the way I read the docs it should only
happen when the base model is abstract or when the inherited
model is proxy model, neither of which is the case. Anyway, the
value returned by save_base for the "comment" from "self" is not 
the value I inserted into the form field (and what has previously 
been saved to Contact object) but is instead an empty string.

The end result is, after Contact object is correctly saved it is,
moments later, overwritten by an empty string. Does anybody have
a clue as to what is happening and most importantly, how can I
avoid it?

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 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/4587198f-5f6f-49a7-b54a-1dcfe5a436ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 2.2 Media files

2019-07-05 Thread Anonymous Anon
I just find it really useful to save it in Google cloud

On Fri., Jul. 5, 2019, 8:25 a.m. John Bagiliko, <
john.bagil...@aims-senegal.org> wrote:

> Since you already configured static folder called media in settings.py, if
> you specifify upload_to='/media', Django will create a folder 'media'
> inside the media folder.
>
> On Fri, Jul 5, 2019, 2:21 PM John Bagiliko 
> wrote:
>
>> Remove the upload_to in the model.
>>
>> On Fri, Jul 5, 2019, 12:55 PM Michał Ratajczak <
>> luminousshado...@gmail.com> wrote:
>>
>>> Hi, i'm new in Django, I'm trying to configure media files correctly.
>>>
>>> That's in my model.py:
>>>
>>> class Question(models.Model):
>>> description = models.CharField(max_length=200)
>>> image = models.ImageField(upload_to='media/', null=True, blank=True)
>>>
>>>
>>> in settings.py:
>>>
>>> STATIC_URL = '/static/'
>>> MEDIA_URL = '/media/'
>>>
>>> ENV_PATH = os.path.abspath(os.path.dirname(__file__))
>>> STATIC_ROOT = os.path.join(ENV_PATH, '../public/static/')
>>> MEDIA_ROOT = os.path.join(ENV_PATH, '../public/media/')
>>>
>>> in urls.py:
>>>
>>> urlpatterns = [
>>> path('admin/', admin.site.urls),
>>> path('', include('barber.urls'))
>>> ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
>>>
>>> in view.py:
>>> def index(request):
>>> images = Question.objects.values('image')
>>> template = loader.get_template('barber/index.html')
>>> context = {
>>> 'images': images
>>> }
>>> return HttpResponse(template.render(context, request))
>>>
>>> I'am adding an image via admin site and next i render in template. Url
>>> for image is "media/image.png" bit file is in .../media/media/image.png, so
>>> i can't understand it. Can anyone help me ?
>>>
>>> --
>>> 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/5613b376-575f-4ab0-bdff-368f0fe8f1cf%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/CAC26BE1jsSya48W0dUgag8XW0eDLjbBjpZW8Ap97mRhq8geNgA%40mail.gmail.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/CAAmw3B329myWM_WCUOs9KDGG50bnqr0KbaysNLfJ-s-xeP10rg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Gravar um valor num atributo novo da models User

2019-07-05 Thread Marcos - GMail
Customizei meus códigos para os demostrados no curso do Gileno Alves Santa
Cruz Filho e ficou muito mais limpo e organizado a parte de customização da
minha model User. O que falta pra mim? Eu criei mais um atributo(campo) de
nome "Role" na minha models.py "Class User" e gostaria de gravar um ou mais
valores, via minha views.py. Para minha views.py eu passo um parâmetro de
nome "origin" que contém por vezes o valor 'Client' ou 'Provider' e é esta
informação que quero atribiu a 'role'. Não consigo!

E anexo os arquivos citados acima. Acredito que uma passada de olho na
views.py vocês vão poder me ajudar

*Marcos Alves*

-- 
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/CAMwkWTP96FRW-BBNtb3uL4j1wDgnCE3EvM6Nhcxhs1JHZnb2zQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
from django.test import TestCase

# Create your tests here.
from django.contrib import admin
from django.urls import path, include
from django.contrib.auth.views import LoginView,LogoutView
from . import views


app_name = 'qnow_user'

urlpatterns = [
#Trabalhando com a view de login do django
path('login_client/',   LoginView.as_view(template_name='../templates/login.html',
 extra_context={'next':'qnow_client:client',
'origin':'client',
'active_page_client_provider':'active'
}
), name="login_client"),
path('login_provider/', LoginView.as_view(template_name='../templates/login.html',
 extra_context={'next':'qnow_provider:provider',
'origin':'provider',
'active_page_client_provider':'active'
}
), name="login_provider"),

path('logout/', LogoutView.as_view(template_name='../templates/index.html',
extra_context={'next_page':'qnow_site:site',
   'active_page_site': 'active',
}),name='logout'),

path('register_client/', views.register, kwargs={'origin': 'client' }, name='register_client'),
path('register_provider/', views.register, kwargs={'origin': 'provider' }, name='register_provider'),
]
from django.contrib import admin
from qnow_user.models import User

admin.site.register(User)from django.apps import AppConfig


class QnowUserConfig(AppConfig):
name = 'qnow_user'
from django.shortcuts import render, redirect
from django.contrib.auth.forms import UserCreationForm, PasswordChangeForm
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required
from django.conf import settings

from .forms import RegisterForm, EditAccountForm

def register(request, origin, *args, **kwargs):
template_name = '../templates/register.html'
if request.method == 'POST':
form = RegisterForm(request.POST)
if form.is_valid():
user = form.save()
user = authenticate(
username=user.username, password=form.cleaned_data['password1']
)
login(request, user)
return redirect('qnow_client:quotation_client')
else:
form = RegisterForm()
context = {
'active_page_client_provider':'active',
'origin': origin,
'form': form
}
return render(request, template_name, context)

import re
from django.db import models
#from django.contrib.localflavor.br.forms import BRStateSelect
from django.core import validators
from django.contrib.auth.models import (AbstractBaseUser, PermissionsMixin,
UserManager)

class User(AbstractBaseUser, PermissionsMixin):

username = models.CharField(
'Usuário', max_length=30, unique=True, 
validators=[validators.RegexValidator(re.compile('^[\w.@+-]+$'),
'O nome de usuário só pode conter letras, digitos ou os '
'seguintes caracteres: @/./+/-/_', 'invalid')]
)
email = models.EmailField('E-mail', unique=True)
name = models.CharField('Nome de Contato', unique=True, max_length=100, blank=False)
is_active = models.BooleanField('Está ativo?', blank=True, default=True)
is_staff = models.BooleanField('É da equipe?', blank=True, default=False)
date_joined = models.DateTimeField('Data de Entrada', aut

Re: Django 2.2 Media files

2019-07-05 Thread Michał Ratajczak
I Remove upload_to and it still wasn't working and next i did in my 
template.html:

{% get_media_prefix as *STATIC_PREFIX* %} <- i added this line because {{ 
item.image }} returns only 'image.jpg'. Now a url is correct :)
{% for item in images %}

{% endfor %}

W dniu piątek, 5 lipca 2019 16:22:22 UTC+2 użytkownik John Bagiliko napisał:
>
> Remove the upload_to in the model.
>
> On Fri, Jul 5, 2019, 12:55 PM Michał Ratajczak  > wrote:
>
>> Hi, i'm new in Django, I'm trying to configure media files correctly.
>>
>> That's in my model.py:
>>
>> class Question(models.Model):
>> description = models.CharField(max_length=200)
>> image = models.ImageField(upload_to='media/', null=True, blank=True)
>>
>>
>> in settings.py:
>>
>> STATIC_URL = '/static/'
>> MEDIA_URL = '/media/'
>>
>> ENV_PATH = os.path.abspath(os.path.dirname(__file__))
>> STATIC_ROOT = os.path.join(ENV_PATH, '../public/static/') 
>> MEDIA_ROOT = os.path.join(ENV_PATH, '../public/media/')
>>
>> in urls.py:
>>
>> urlpatterns = [
>> path('admin/', admin.site.urls),
>> path('', include('barber.urls'))
>> ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
>>
>> in view.py:
>> def index(request):
>> images = Question.objects.values('image')
>> template = loader.get_template('barber/index.html')
>> context = {
>> 'images': images
>> }
>> return HttpResponse(template.render(context, request))
>>
>> I'am adding an image via admin site and next i render in template. Url 
>> for image is "media/image.png" bit file is in .../media/media/image.png, so 
>> i can't understand it. Can anyone help me ?
>>
>> -- 
>> 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 post to this group, send email to django...@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/5613b376-575f-4ab0-bdff-368f0fe8f1cf%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/db65491a-9c80-4809-a6b5-9a29c23e6427%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 2.2 Media files

2019-07-05 Thread Jani Tiainen
Hi.

What you did is correct and expected.

Upload_to is relative path to MEDIA_ROOT in case of normal file upload
backend. There are many others like S3.

Now MEDIA_URL is absolute path of web server which points to MEDIA_ROOT. In
development you can use static file serving trick like you did.

Now when getting url in template you should use something like {{ image.url
}} which should render correct absolute url to your  uploaded file.

HTH.

pe 5. heinäk. 2019 klo 15.55 Michał Ratajczak 
kirjoitti:

> Hi, i'm new in Django, I'm trying to configure media files correctly.
>
> That's in my model.py:
>
> class Question(models.Model):
> description = models.CharField(max_length=200)
> image = models.ImageField(upload_to='media/', null=True, blank=True)
>
>
> in settings.py:
>
> STATIC_URL = '/static/'
> MEDIA_URL = '/media/'
>
> ENV_PATH = os.path.abspath(os.path.dirname(__file__))
> STATIC_ROOT = os.path.join(ENV_PATH, '../public/static/')
> MEDIA_ROOT = os.path.join(ENV_PATH, '../public/media/')
>
> in urls.py:
>
> urlpatterns = [
> path('admin/', admin.site.urls),
> path('', include('barber.urls'))
> ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
>
> in view.py:
> def index(request):
> images = Question.objects.values('image')
> template = loader.get_template('barber/index.html')
> context = {
> 'images': images
> }
> return HttpResponse(template.render(context, request))
>
> I'am adding an image via admin site and next i render in template. Url for
> image is "media/image.png" bit file is in .../media/media/image.png, so i
> can't understand it. Can anyone help me ?
>
> --
> 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/5613b376-575f-4ab0-bdff-368f0fe8f1cf%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/CAHn91odFeKH_FkZAuJ73w4scBbicSYsV%2BSpCD74P07Y%2B-%3DjC6A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: saving inherited model overwrites base model

2019-07-05 Thread Jani Tiainen
Hi.

I think you have a bit confused terms model inheritance and abstract models.

Normal model inheritance in Django means that there will be implicit one to
one relation to base model. Inherited model still receives all fields from
parent model. On save data is just saved to correct models. To both parent
and child. And both models do have separate tables.

If inherited model is abstract all fields are copied to inherited model and
django treats model as one. There is no parent table created but columns
are added to inheriting model table.

pe 5. heinäk. 2019 klo 20.42 Kalev Takkis 
kirjoitti:

> Hi all,
>
> tl;dr: saving inherited model overwrites fields in parent models with
> empty strings
>
> I have the following models:
>
> class Contact(models.Model):
> comment = models.CharField(max_length=255, blank=True)
> emails = models.ManyToManyField(
> Email,
> blank=True,
> through='ContactEmail',
> through_fields=('contact', 'email'),
> )
>
> # couple of more manytomanys, to addresses, phones, etc
>
>
> class ContactEmail(BaseContactJunctionModel):
> email = models.ForeignKey(Email, null=True, on_delete=models.SET_NULL)
> contact = models.ForeignKey(Contact, on_delete=models.CASCADE)
> event = models.ForeignKey(ContactEvent, on_delete=models.PROTECT)
> event_date = models.DateTimeField(default=timezone.now)
>
>
> # other similar through tables for the rest of the manytomanys and their
> target models
>
>
> class Organisation(Contact):
>
> name = models.CharField(max_length=255, blank=True)
> hierarchy = models.ManyToManyField(
> 'self',
> blank=True,
> symmetrical=False,
> through='OrganisationHierarchy',
> through_fields=('sender', 'target'),
> )
>
> # again, more manytomanys, not to self though
>
> # not sure this is relevant but as it's to self, then just in case
> class OrganisationHierarchy(BaseContactJunctionModel):
> # this, instance that specifies relationship
> sender = models.ForeignKey(
> Organisation,
> null=True,
> related_name='senders',
> on_delete=models.SET_NULL,
> )
>
> # instance that 'this' or 'sender' is related to
> target = models.ForeignKey(
> Organisation,
> null=True,
> related_name='targets',
> on_delete=models.SET_NULL,
> )
>
> connection_type = models.ForeignKey(
> ConnectionType,
> null=True,
> on_delete=models.PROTECT,
> )
>
> I have a view based on CreateView and a template to capture user
> input. The post request coming from browser is a-ok, saving
> emails, contact, contactemails and other manytomany targets and
> junction tables works without a problem but when getting to
> saving Organisation, this happens (pseudocode):
>
> save() is called from django/db/models/base.py
> save_base() is called with self=Organisation
> save_base calls _save_parents(self=Organisation, cls=Organisation)
> save_parents loops through cls._meta.parents and comes across
> relation
> parent=Contact, field=Organisation.contact_ptr
> calls _save_table with self=Organisation and cls=Contact
> _save_table finds from cls._meta that it has
> local concrete field "comment" and stores it in list
> non_pks
> it then finds the values for those fields like
> this:
> f.pre_save(self, false) for f in non_pks
>
> I then see a call to _update in queries.py and Contact instance
> is updated with new values.
>
> I don't really understand what's happening here, the code finds
> local concrete fields from "cls" which at this point is Contact
> and comes up, correctly, with "comment" but then it tries to
> query the field value form "self" which at this point is
> Organisation object. I'm not sure why Organisation has "comment"
> attribute at all, because the way I read the docs it should only
> happen when the base model is abstract or when the inherited
> model is proxy model, neither of which is the case. Anyway, the
> value returned by save_base for the "comment" from "self" is not
> the value I inserted into the form field (and what has previously
> been saved to Contact object) but is instead an empty string.
>
> The end result is, after Contact object is correctly saved it is,
> moments later, overwritten by an empty string. Does anybody have
> a clue as to what is happening and most importantly, how can I
> avoid it?
>
> 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 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 vis

Re: Django 2.2 Media files

2019-07-05 Thread Michał Ratajczak
Oh yeah! That's it ! Big thank's for you :)

W dniu piątek, 5 lipca 2019 22:14:52 UTC+2 użytkownik Jani Tiainen napisał:
>
> Hi.
>
> What you did is correct and expected.
>
> Upload_to is relative path to MEDIA_ROOT in case of normal file upload 
> backend. There are many others like S3.
>
> Now MEDIA_URL is absolute path of web server which points to MEDIA_ROOT. 
> In development you can use static file serving trick like you did.
>
> Now when getting url in template you should use something like {{ 
> image.url }} which should render correct absolute url to your  uploaded 
> file.
>
> HTH.
>
> pe 5. heinäk. 2019 klo 15.55 Michał Ratajczak  > kirjoitti:
>
>> Hi, i'm new in Django, I'm trying to configure media files correctly.
>>
>> That's in my model.py:
>>
>> class Question(models.Model):
>> description = models.CharField(max_length=200)
>> image = models.ImageField(upload_to='media/', null=True, blank=True)
>>
>>
>> in settings.py:
>>
>> STATIC_URL = '/static/'
>> MEDIA_URL = '/media/'
>>
>> ENV_PATH = os.path.abspath(os.path.dirname(__file__))
>> STATIC_ROOT = os.path.join(ENV_PATH, '../public/static/') 
>> MEDIA_ROOT = os.path.join(ENV_PATH, '../public/media/')
>>
>> in urls.py:
>>
>> urlpatterns = [
>> path('admin/', admin.site.urls),
>> path('', include('barber.urls'))
>> ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
>>
>> in view.py:
>> def index(request):
>> images = Question.objects.values('image')
>> template = loader.get_template('barber/index.html')
>> context = {
>> 'images': images
>> }
>> return HttpResponse(template.render(context, request))
>>
>> I'am adding an image via admin site and next i render in template. Url 
>> for image is "media/image.png" bit file is in .../media/media/image.png, so 
>> i can't understand it. Can anyone help me ?
>>
>> -- 
>> 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 post to this group, send email to django...@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/5613b376-575f-4ab0-bdff-368f0fe8f1cf%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/ce8050ee-be00-449d-86c5-7285888e6f2d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to convert files from .bin to .png with Python or Django

2019-07-05 Thread Joe Reitman
Try using the Pillow library. 

On Wednesday, July 3, 2019 at 6:52:35 PM UTC-5, Fernando Garrido Villalobos 
wrote:
>
> How to create a function that have like argument the path of a .bin file 
> and returns a .png file ...
> I need your help, 
> thank you so much.
>

-- 
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/c70349c1-2840-4175-8ad0-f51947bb1924%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.