Re: Error messages in SetPasswordForm

2020-02-05 Thread Daniel Germano Travieso
It is my belief, if I remember correctly, that the construct _()
allows for usage of unicode direct text, and such, makes it possible to
directly insert any special characters in the text. So for ease of
understanding, the special character was used in a way that does not
confuse the reader and spares them of trying to parse/remember what the
construction of escaped characters are.

But I could be wrong as I do not work on the belly of Django development.
*[]'s*
Daniel Germano Travieso

-BEGIN PGP PUBLIC KEY BLOCK-

mQINBF1hSUIBEAC56ve8/8fAt55s+PHuolumg8zvjqk0cpo36DXkntP1fqlY5DdP
36sfvL/pJgt+x480Wy6YVdj1T/N7c3WxcUx6D+oh8ZBmeG2eoeJli1BT/QDrLyt/
af0djw/VMc5ygV0Lg6zg8ynNn+mjhcDMFyl7ITZeYgXXX3fO7I87geAdWmb9sX4W
C7qfRi23PQZ/0vKlv9WSlzvOMDcB0g3aoxuYmhbZ5KlRlrQYVeW1rcQHP6CGrVFs
9/FAvjw2rj+vsS7w0CjmF1Q5XZ/MWrx3I17RXojkBeDQElLA7y732G4wk7WS60wE
NLuEclHieSs780bWdIRwYW7i0mmYAjnO9eRzMfhRtykcbJBy0Nodr1c15Qa2LKFr
ZUk9kil3utKTYaU3kUbe+M2VQXthw0Vvb5NWagsNAZdOwBWsHY56bvsy5pCUtS9a
NE8WZEt8UEU4IF93RATMXl+BxtIgQOWDPmXkt/bqLk4U01+70AFdszanGkyZgFyn
VOr44gBM9+78SEOf/exiKLnZuv4VEtt5fUniwRkSSRaMCuEVk3JlBAbVY22d9Lzu
c3i6g2yWZuqIXnsIwhw/g62uDE+yWGnYzM5Kn8fCAkmcyKG8qHSlqtiOnN0yzMj0
aV1DZ5pR3MESa0HWQnechUvnD0KdT/pD3qOvHZYsbOTXqDz6J+r3JK1+FQARAQAB
tE1EYW5pZWwgR2VybWFubyBUcmF2aWVzbyAoRGFuaWVsIFRyYXZpZXNvJ3MgSW5i
b3gpIDxkYW5pZWxndHJhdmllc29AZ21haWwuY29tPokCVAQTAQgAPhYhBAeImfqY
0eaSaZ3kJtqQme6v6yE1BQJdYUlCAhsDBQkJZgGABQsJCAcCBhUKCQgLAgQWAgMB
Ah4BAheAAAoJENqQme6v6yE1Yu8P/RK5CY5Pxo2u+0ulw1MDU0AeFyb8sHGqFHCG
LGjReaGmG3HY5rzEOYsgfcPCAUz5P03Qj3Peypr2QN4RAJnOXTUJINmPjxsDfp2O
2z4p6gt9rCDhschoIIJSuy3LyZdfNQN/8jMGMY5wslV6UA1s5+AEFNJ0H3n372Em
hvrAj2ZRG35/tSzkHNqPpNNJWxEQK/UL0JwBIdkf1OG3sTTphOoyuqjTtn1rRp42
7xBGHh8diidJazFY0gDLr9hoXZSDuj8MTvY5MsnT3rsaNnDfXQWqo+cJyySOGWLi
C03dQ0ynIbdRCWyKNsgPnxQAVxzGINxTmk2zk1M6RIO26y6oC1zEQ3WhZm2HnjlM
pnjb3gST2q5VshRToQ22eZc8JGFFldsRiNGh4rtgMu5xvtD36THz58lqXn4CcP9Z
TNoVBuSAd7V6RwZDi38fI4ePUxJQrywk4xcT8gr8tLNjadtcwgGpotoX7xVamP/I
Dj3URPWUW4dhXTHcXj2TQvw1+yFEGvwRqs2NPySlZA5xv5Z3oyQdoKXAD44Amcop
Tvaimw1599EtVMdy5mSNCXuSKckUT9E/lg2aqOJSDbZBJRO4F7ERK+Zl54mxrnKm
ESwM5P8WDUreYRTOLjNF0aONjcYrWYpNCEzxHKfKN0w6+oSv/oCZY3lgIgUz11Mo
9A20mUwDuQINBF1hSUIBEADAmuIB3JUmtpXuzYCEqGl3vLWokxVYsRBSyFE9UqOw
XEXgvBaVPtBoAaEPiYl1ZcjlWa1gVpKRs3uNzgpZq/tUwXXJ57Gb60FZIlysYTwK
AOIt6huTt+ePh3gV1V+8Q7avQxwnqkR17pllwuxT4YxUhiAownd+saHWzt4zvNkn
31jk3FlkJN7YHiW6qZYBfIqBhcRen/Jx4G7WjznGQrPcUW6xTw8yQePRKXMOqMHM
+Na2ZMKdAx+hV8ZVguwfYJd/D1LhyUZQJ+tZIjtrXAtX2piKgMP9mgjHDrm2gTjj
EMsVfeH+J5HzsRFNWW7BV4ZNt8IrmU8j9TFGYB+CbhNPLqFnSgV4MeMBDP86Nlkh
DK27CYguNqPb3+7SjA85V6+JzEjYz8Xc860VYiw6e953bByu2FsPGXanggM8+CQQ
qjd6ApT921h76raVXQ/VsHctE/DYDwdBppTMk23WMLyGR3rpTUINM7NmmhCuOK2i
LhWq09TE48byxImSnwRpTxCSumhApIi76edDjmlKNqO9hNBArHs+03ExbjOWaQre
xynThWwcVN9FdqGL6CfIVEgk4FihNIlvVeu1AN1YcwYBtgSyc8Iz6NymngqgYkOI
STZ3wrMXaA17bfT+OTPebxRBzW43/BeoHVXkwhY+h+pWdjaEvbJWAzVl+CGfrgUt
OQARAQABiQI8BBgBCAAmFiEEB4iZ+pjR5pJpneQm2pCZ7q/rITUFAl1hSUICGwwF
CQlmAYAACgkQ2pCZ7q/rITW09g//Zl3QOtt+e5swVD3Vp7sZiGiueiJQVieVdY1F
JJFnpgZxyLn3fBAyc1dgBP/k9hUVwQUP/415zr+6zRYROku7lLXGDTaDHbkAprEL
m8HTBfYdyhSk5JW8W1luylkzB/6beIytxG28Y02xG+1X0t3k86la8FGfYBIYcNrX
2RwFjUt5FGMcGOtoU45/RcDOUEOxdMcCJQhpgavONpBDMjEIPVYUi8CPnJR/HUkO
FRHf/9S22mnNG8m/+jMC4TaM2OzU70yfW7u3n9UcHracSc6CbdMayXD//NHpOQtL
hP/K1G+azAQKwb/+n22U7M7mQets6VVOu5x9VOkpsK26CwZ79pB7DaJicaunO8Nl
VG/DCRDGhk207ULQdA0jMr6XDofYA/9mleFRp3UVoIp5DTNa/eivXZQhzWtkW66s
RUB2Du3S2shyhuOIxRW5M4zgUNMe8pDTQRbm0oBfrFjoX7K+F5G4wgaEnXqp3d6O
WzzgvqYDzTqkJtyfF0A8PaiYWyBpOa6zTNtRwkrxsL+Ley/dRyMZeeCG20gsuHqy
DOLjz01uVuOg2B7+oJrYQkBMYc/n9s9z+O0GjQR+WKan1NgSwrSedPd52/FiPvT1
PPqlAem1Xs8EfBDgdVT4u1nbItbJGfR+5OU6xAgDH09ylwmV6bnOJtHFzjnqUK7P
4buoGc4=
=bYtC
-END PGP PUBLIC KEY BLOCK-



Em qua., 5 de fev. de 2020 às 14:40, One Above All <
the.one.above.all.ti...@gmail.com> escreveu:

> In *django.contrib.auth.forms* there is a class named *SetPasswordForm*
> which has a dictionary member *error_messages*. It is defined as follows:
> *error_messages = {*
> *'password_mismatch': _('The two password fields didn’t match.'),*
> *}*
> A special character has been used for apostrophe instead of \' . Is this a
> design decision? It might create extending this class further and
> development difficult for new comers.
> If I am missing something or it is already known kindly provide reference
> to that.
>
> Regards,
> Gagan Deep
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8847e13f-3d31-40e3-aed0-e5b06ce7b3f8%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/8847e13f-3d31-40e3-aed0-e5b06ce7b3f8%40googlegroups.com?utm_medium=email&utm_source

Re: Trouble adding users through admin site

2018-06-09 Thread Daniel Germano Travieso
Hello Dylan

You will never see a user password as a raw text on django (only maybe if
you intercept the request the user creation form sent to the django view
that handles the creation)

User passwords are stored as their appropriate hash, and you can just use
the add user admin page to add a new user to your project (setting first
it's username and password and then the other settings).

Also, if you are using a custom User model that inherits AbstractUser, you
need to set it's UserAdmin (from django.contrib.auth.admin) via the
admin.py

You also need the setting AUTH_USER_MODEL to point to your custom User and
do this before creating or running any migrations or migrating

Check out the official docs [0] on the matter to learn more!

Also on an important note:
User passwords are not displayed in the admin (nor stored in the database),
but the password storage details are displayed. Included in the display of
this information is a link to a password change form that allows admins to
change user passwords [1]


[0]
https://docs.djangoproject.com/en/2.0/topics/auth/customizing/#using-a-custom-user-model-when-starting-a-project
[1] https://djangobook.com/managing-users-admin/



On Sat, Jun 9, 2018, 18:38 Dylan Moreland 
wrote:

> Hello!
>
> I've created a Django app for my company to track employee infractions
> (missed punch, late to a shift, etc.), but I'm at a roadblock in terms of
> adding users. Currently, the only way I can add users is through the
> command line. I'd much rather be able to add users through the
> django.contrib.admin site. However, I've found that if I input a password
> there, it treats is as the value to enter into the database (post
> hashing/salting/etc.) rather than raw text. This obviously does not work.
>
> I'm using an AbstractUser model called Employee to represent users instead
> of the default User model. This is just so I have the option of customizing
> my model down the road if need be without having to deal with broken
> ForeignKey relationships.
>
> If this were on the frontend, I would write a view that would take the raw
> password and send it through set_password(), and that would be the end of
> it. But I'm not sure how to do that with the admin site.
>
> *Models.py:*
> from django.db import models
> from django.contrib.auth.models import AbstractUser
>
> # Create your models here.
> class Employee(AbstractUser):
>  def __str__(self):
>  return self.first_name
>
> class InfractionType(models.Model):
>  description = models.CharField(max_length=30)
>
>  def __str__(self):
>  return self.description
>
>
> class Infraction(models.Model):
>  timestamp = models.DateTimeField()
>  employee = models.ForeignKey(Employee, on_delete=models.CASCADE)
>  type = models.ForeignKey(InfractionType, on_delete=models.CASCADE)
>  has_comment = models.BooleanField(default=False)
>  description = models.CharField(max_length=200)
>
>  def __str__(self):
>  return str(self.employee) + ": " + self.description
>
>
> *Admin.py:*
> from django.contrib import admin
>
> # Register your models here.
> from .models import Employee, InfractionType, Infraction
>
> class InfractionInline(admin.TabularInline):
>  model = Infraction
>  extra = 0
>
> class EmployeeAdmin(admin.ModelAdmin):
>  fieldsets = [
>  ('Authentication and Metadata', {'fields': ['username', 'first_name',
> 'last_name', 'email', 'groups', 'is_staff', 'is_active'], 'classes': [
> 'collapse']}),
>
>  ]
>  inlines = [InfractionInline]
>
>  # Prevent users from getting deleted (should be made inactive instead)
>  def has_delete_permission(self, request, obj=None):
>  return False
>
> admin.site.register(Employee, EmployeeAdmin)
> admin.site.register(InfractionType)
>
> What I see on the admin site:
>
>
> 
>
> 
> 
>
>
> Thanks for your 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/974890d1-9492-45a1-b3d9-6ba09558cbd0%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.

Re: bootstrap to the login template

2018-06-06 Thread Daniel Germano Travieso
Hey!

You should check the documentation
https://docs.djangoproject.com/en/2.0/topics/forms/#working-with-form-templates
for the Forms that django uses. Each form has it's fields as attributes
that generate the input tag that will house the input you receive.

You could, for example, create a customize the User login form, and use the
attrs attributes for the widget class of each field
https://docs.djangoproject.com/en/2.0/ref/forms/widgets/

There are also some handy django apps that can make your life easier, for
example this one
https://github.com/jazzband/django-widget-tweaks/blob/master/README.rst
that enables you to set the class attribute off the template tag.

I recommend you to try first to do it yourself, as a learning experience
and then use the django-widget-tweaks when you understand what goes behind
setting custom widget attrs.


Hope it helps!

On Wed, Jun 6, 2018, 17:59 G.R. Nobles  wrote:

> Below are two forms, the login form (top) and a bootstrap form (bottom),
> I'm trying to apply bootstrap to the login page, how can I integrate
> bootstrap onto the login objects, e.g. {{ form.username }} is the entire
> textbox, so I'm at a loss being a beginner with Django (my first week).
>
> {% if form.errors %}
> Your username and password didn't match. Please try again.
> {% endif %}
>
> {% if next %}
> {% if user.is_authenticated %}
> Your account doesn't have access to this page. To proceed,
>   please login with an account that has access.
>   {% else %}
>   Please login to see this page.
>   {% endif %}
>   {% endif %}
>
>   
> {% csrf_token %}
> 
>   {{ form.username.label_tag }}
>   {{ form.username }}
> 
> 
>   {{ form.password.label_tag }}
>   {{ form.password }}
> 
>   
>   
> 
>   
>   
> 
>  required autofocus>
>  placeholder="Password" required>
> 
>   Sign in
>   
> 
> Remember me
>   
>   Need 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/3aa17d90-3959-4b16-8c14-93c966fb45d0%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/3aa17d90-3959-4b16-8c14-93c966fb45d0%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
-- 
[]'s
Daniel Germano Travieso
Engenharia de Computação UNICAMP

-- 
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/CABF8kZOMvAq8FruUKc6kQ%2Bbyq_G%3Dz9%3DJ38_LCM5A0PgE0zppOA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing the model attribute of UpdateView & friends

2018-06-06 Thread Daniel Germano Travieso
I'm glad it helped.

As you can see, the dispatch method I wrote does override the default
definition, but I return the super() dispatch method, so on the default
flow the end result is the same (the validity of the request would be
checked anyway, only after you set your class atribute).
To avoid this work that would be invalid if there is an error on the
request you could write a dispatch method that first gets the result of the
super (). dispatch, check if it was ok then do the work you need and return
the result of the dispatch after that.

And you could as well use the __init__ method for the class, but I'm not
sure the .as_view() function works as a constructor like that, I would need
to confirm the documentation, but there were some implementations that I
worked with that customized the __init__ of the view class so it would
probably work. A more philosophical question is if it is the proper
location for that work to be done, as the __init__ method could be called
even if the request is invalid, making your code try to do something weird.

Anyway, good luck on your project!

On Wed, Jun 6, 2018, 14:51 Mikkel Kromann  wrote:

> Thanks Daniel.
>
> Both your proposed solutions worked very well.
> For now, I don't have other information stuffed into my model definitions,
> so the urls.py approach could do.
> However, if I decide to put more information into models.py, the def
> dispatch() approach could be useful.
>
> One question though:
> Do I understand correctly, that your version of def dispatch() overwrites
> the Django dispatch method from UpdateView.
> As far as I can see, it checks the validity of the request method.
> Could I use def __init__ instead of def dispatch
>
>
> thanks + cheers, Mikkel
>
>
> From
> https://ccbv.co.uk/projects/Django/2.0/django.views.generic.edit/UpdateView/
> def dispatch(self, request, *args, **kwargs):
> # Try to dispatch to the right method; if a method doesn't exist,
> # defer to the error handler. Also defer to the error handler if the
> # request method isn't on the approved list.
> if request.method.lower() in self.http_method_names:
> handler = getattr(self, request.method.lower(), self.
> http_method_not_allowed)
> else:
> handler = self.http_method_not_allowed
> return handler(request, *args, **kwargs)
>
>
>
>
> onsdag den 6. juni 2018 kl. 16.12.06 UTC+2 skrev Daniel Germano Travieso:
>
>> Ok! I think I see your problem.
>>
>> It is a deeper understanding of python classes that may be the problem.
>> You see, "model" and "self" are class atributes of the python class that
>> houses your class based view (as every class in django is first a python
>> class).
>>
>> So, if you try to access the attribute "model" of the class, or the
>> attribute "self", a attribute that houses the instance of the class, on
>> it's class attributes definitions you will have problems, as the python
>> interpreter only load these modules lazyly, not actually going through on
>> finding the value for the attribute you referenced.
>>
>> One solution is to have that value (for the attribute "field" as a
>> @property that is a function that then the python interpreter will go
>> through and execute the reference lookup.
>>
>> Another solution is to set that value to be initially None, and set the
>> value for the fields on the dispatch method of the view, something like
>> class ItemUpdateView(UpdateView):
>>   template_name="foo.html"
>>   fields = None
>>
>>   def dispatch (self, request, *args, **kwargs):
>> self.fields = self.model.fields
>> return super(ItemUpdateView, self).dispatch(request, *args, **kwargs)
>>
>>
>>
>> But as of my understanding of your problem, you are trying to just
>> customize which form fields to display to the user based on which model the
>> user is updating, so you could just specify the form_class attribute on the
>> path (just as you did with the model).
>>
>> Hope it helps!
>>
>>
>> On Wed, Jun 6, 2018, 10:36 Mikkel Kromann 
>> wrote:
>>
> Hello Daniel.
>>>
>>> Thank you for your reply. Perhaps I was not explicit enough in
>>> describing my problem - it is far simpler than your solution indicates.
>>> In my model definitions, I already have a list of the fields to be
>>> represented in the form of UpdateView - it is an attribute in the form of a
>>> simple array called "fields".
>>> I don't want UpdateView to make a form for all columns of the model's
>>> data table, just the

Re: Not Found: / [06/Jun/2018 19:45:16] "GET / HTTP/1.1" 404 2027 Not Found: /favicon.ico

2018-06-06 Thread Daniel Germano Travieso
You probably need to set up your static files on Django.

Take a look at the documentation for static file serving.

On Wed, Jun 6, 2018, 11:59 Avitab Ayan Sarmah  wrote:

> what is this means? and hw do i resolve this error? Please comment.And
> also my image is not open in my webpage when i have added an image with
> black background with .gif suffix.How do i resolve it?
>
> --
> 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/54fbc10d-922c-458f-8264-336d081352ba%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/CABF8kZPTb4JmW33yF_geGHqrhDiv5anY5n3DFk_FcKVRnjpiUg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Accessing the model attribute of UpdateView & friends

2018-06-06 Thread Daniel Germano Travieso
Ok! I think I see your problem.

It is a deeper understanding of python classes that may be the problem.
You see, "model" and "self" are class atributes of the python class that
houses your class based view (as every class in django is first a python
class).

So, if you try to access the attribute "model" of the class, or the
attribute "self", a attribute that houses the instance of the class, on
it's class attributes definitions you will have problems, as the python
interpreter only load these modules lazyly, not actually going through on
finding the value for the attribute you referenced.

One solution is to have that value (for the attribute "field" as a
@property that is a function that then the python interpreter will go
through and execute the reference lookup.

Another solution is to set that value to be initially None, and set the
value for the fields on the dispatch method of the view, something like
class ItemUpdateView(UpdateView):
  template_name="foo.html"
  fields = None

  def dispatch (self, request, *args, **kwargs):
self.fields = self.model.fields
return super(ItemUpdateView, self).dispatch(request, *args, **kwargs)



But as of my understanding of your problem, you are trying to just
customize which form fields to display to the user based on which model the
user is updating, so you could just specify the form_class attribute on the
path (just as you did with the model).

Hope it helps!


On Wed, Jun 6, 2018, 10:36 Mikkel Kromann  wrote:

> Hello Daniel.
>
> Thank you for your reply. Perhaps I was not explicit enough in describing
> my problem - it is far simpler than your solution indicates.
> In my model definitions, I already have a list of the fields to be
> represented in the form of UpdateView - it is an attribute in the form of a
> simple array called "fields".
> I don't want UpdateView to make a form for all columns of the model's data
> table, just the fields from my custom array in the Model objects.
>
> My problem is simply: How to access my custom attribute "field" in the
> Model attribute passed to the Class Based View function.
> As described, I get compilation errors, complaining that "model" and
> "self" are names not defined.
> From the documentation (and my so far not too great Python understandign)
> it is not clear to me whether "Model" is simply the name of the model, or
> if it is the entire Model object instance.
>
>
> thanks again, Mikkel
>
>
> onsdag den 6. juni 2018 kl. 15.01.05 UTC+2 skrev Daniel Germano Travieso:
>>
>> Hello!
>>
>> As you see on the documentation (
>> https://docs.djangoproject.com/en/2.0/topics/class-based-views/) for the
>> class based views, any arguments you pass to the class based view
>> .as_view() method will override attributes of the class based view, so if
>> you set MyCView.as_view(model=Foo) is the same as setting class MyCView:
>> model=Foo directly.
>>
>> Now to access the field names of the Model, you used to be able to call a
>> .get_field_names() or something like that but that is depreciated since
>> 1.10. Now to do that you should use the Model._meta to get_fields(). Check
>> the documentation for the Model._meta to check its full potential.
>>
>> Hope it helps!
>>
>> On Wed, Jun 6, 2018, 07:33 Mikkel Kromann 
>> wrote:
>>
>>> Thanks for the advice, Andréas.
>>> But the response is the same:
>>>
>>>   File "C:\Users\ ... xxx   ... \items\views.py", line 7, in
>>> ItemUpdateView
>>> fields = self.model.fields
>>> NameError: name 'self' is not defined
>>>
>>>
>>>
>>> As far as I understood, model is an attribute, not a method (though I'm
>>> new to Python and Django, so I'm unsure about this).
>>> Does attribute/method make a difference in this case?
>>>
>>> cheers, Mikkel
>>> tirsdag den 5. juni 2018 kl. 22.10.31 UTC+2 skrev Andréas Kühne:
>>>>
>>>> Hi,
>>>>
>>>> Have you tried self.model? It should be present in all methods in the
>>>> class?
>>>>
>>>> Regards,
>>>>
>>>> Andréas
>>>>
>>>> 2018-06-05 21:56 GMT+02:00 Mikkel Kromann :
>>>>
>>>>> Dear Django-users.
>>>>>
>>>>> I'm slowly working towards a Django "data-warehouse" framework, where
>>>>> I can easily add a lot of models (each containing a table with data), 
>>>>> while
>>>>> sticking to only few reusable views.
>>>

Re: Accessing the model attribute of UpdateView & friends

2018-06-06 Thread Daniel Germano Travieso
Hello!

As you see on the documentation (
https://docs.djangoproject.com/en/2.0/topics/class-based-views/) for the
class based views, any arguments you pass to the class based view
.as_view() method will override attributes of the class based view, so if
you set MyCView.as_view(model=Foo) is the same as setting class MyCView:
model=Foo directly.

Now to access the field names of the Model, you used to be able to call a
.get_field_names() or something like that but that is depreciated since
1.10. Now to do that you should use the Model._meta to get_fields(). Check
the documentation for the Model._meta to check its full potential.

Hope it helps!

On Wed, Jun 6, 2018, 07:33 Mikkel Kromann  wrote:

> Thanks for the advice, Andréas.
> But the response is the same:
>
>   File "C:\Users\ ... xxx   ... \items\views.py", line 7, in
> ItemUpdateView
> fields = self.model.fields
> NameError: name 'self' is not defined
>
>
>
> As far as I understood, model is an attribute, not a method (though I'm
> new to Python and Django, so I'm unsure about this).
> Does attribute/method make a difference in this case?
>
> cheers, Mikkel
> tirsdag den 5. juni 2018 kl. 22.10.31 UTC+2 skrev Andréas Kühne:
>>
>> Hi,
>>
>> Have you tried self.model? It should be present in all methods in the
>> class?
>>
>> Regards,
>>
>> Andréas
>>
>> 2018-06-05 21:56 GMT+02:00 Mikkel Kromann :
>>
>>> Dear Django-users.
>>>
>>> I'm slowly working towards a Django "data-warehouse" framework, where I
>>> can easily add a lot of models (each containing a table with data), while
>>> sticking to only few reusable views.
>>>
>>> I've realised that in urls.py, it is possible to specify the model on
>>> which the UpdateView is going to do its magic.
>>> This allows me to use a generic UpdateView (which I called
>>> ItemUpdateView) and template for all my models, which will save me a ton of
>>> almost identical lines of code.
>>>
>>> However, in the generic ItemUpdateView, I of course need to specify the
>>> fields of the specific model chosen in urls.py.
>>> As I ideally only want a few generic views (i.e. ItemCreateView,
>>> ItemUpdateView, ItemDeleteView and ItemListView), I've chosen to place the
>>> field array in my model definition, hoping to be able to access it from my
>>> generic Class Based Views
>>>
>>> But how do I access the model attribute in (Item)UpdateView
>>>
>>>
>>> thanks, Mikkel
>>>
>>> From views.py
>>> from django.views.generic import CreateView, ListView, UpdateView,
>>> DeleteView
>>>
>>> class ItemUpdateView(UpdateView):
>>> template_name = "item_form.html"
>>> # How do I access the model attribute of ItemUpdateView as given in
>>> urls.py?
>>> # This line below returns the error "NameError: name 'model' not defined"
>>> fields = model.fields
>>>
>>> From urls.py
>>> from django.urls import path
>>> from . views import ItemUpdate
>>> from . models import Region, Location
>>>
>>> # Awesome! I can specify the model to be used by ItemUpdateView
>>> urlpatterns = [
>>> path('update/region/',ItemUpdateView.as_view(model=Region),
>>> name='region_update'),
>>> path('update/location/',  ItemUpdateView.as_view(model=Location
>>> ),   name='location_update'),
>>> ]
>>>
>>>
>>>
>>> From models.py (Region and Location are only two of my tables, I'd like
>>> to have say 20 or 30 models
>>> from django.db import models
>>>
>>> # Abstract class for our items including common methods, data and
>>> definitions
>>> class ItemModel(models.Model):
>>>
>>> fields = [ 'label', 'short', 'descr' ]
>>> label   = models.CharField(max_length=10)
>>> short   = models.CharField(max_length=15)
>>> descr   = models.CharField(max_length=40)
>>>
>>> def __str__(self):
>>> return self.short
>>>
>>> class Meta:
>>> abstract = True
>>>
>>> class Region(ItemModel):
>>> fields  = [ 'label', 'short', 'descr' ]
>>>
>>> class Location(ItemModel):
>>> fields  = [ 'label', 'short', 'descr', 'region' ]
>>> region  = models.ForeignKey(Region, on_delete=models.CASCADE)
>>>
>>> class Plant(ItemModel):
>>> fields  = [ 'label', 'short', 'descr', 'location', 'capex', 'opex',
>>> 'capacity' ]
>>> location= models.ForeignKey(Location, on_delete=models.CASCADE)
>>> capex   = models.DecimalField(decimal_places=3, max_digits=8)
>>> opex= models.DecimalField(decimal_places=3, max_digits=8)
>>> capacity= models.DecimalField(decimal_places=3, max_digits=8)
>>>
>>>
>>> --
>>> 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...@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/ec4634e5-2279-49a7-9045-21712de87584%40googlegroups.com

Re: Upload video with automatically created thumbnail in Django 2

2018-06-06 Thread Daniel Germano Travieso
Hello!

This type of video rendering and processing should be done by a python
module that can handle this workload.

For example, you can use OpenCV, a C++ computer vision module that has a
python hooks version, so you can upload your video via django the usual way
an use the OpenCV to process the video and extract a frame for the
thumbnail (a function like cv2.VideoCapture) on the view that handles the
upload.

Please beware of a possible overhead on your server's processing power as
video rendering tools are always CPU bound.

Hope it helps.

On Wed, Jun 6, 2018, 06:35 Pravin Yadav  wrote:

> Hi Sir,
>
> is it possible to create only one thumbs image. If any one know kindly
> help me. I'm not getting any solutions. Plz
> help...
>
>
> Thanks,
> Pravin Yadav
>
>
> On Tuesday, June 5, 2018 at 6:54:15 PM UTC+5:30, HaatBhaar Developer wrote:
>>
>> Hello dude,
>> I wish I could solved your problem. But right now I don't have that idea.
>> Hope fully I will find that for you and will give the solution.
>> May your next problem I can solve.
>>
>> On 5 June 2018 at 17:40, Pravin Yadav  wrote:
>>
>>> I want to upload .mp4 and .mov videos in my django website with
>>> automatic thumbnail generation. Thumbnails should be created in .jpg or
>>> .png that will be saved in ImageField and also video in FileField.
>>>
>>> I'm using Python 3.6.1 and Django 2.0.
>>>
>>> Please advise me how to create a video similar to youtube.
>>>
>>> Is there any opensource modules/plugins available for this this ?
>>>
>>> Kindly, Help me.
>>>
>>>
>>> Thanks,
>>>
>>>
>>> Pravin Yadav
>>>
>>>
>>>
>>> --
>>> 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...@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/1713df71-5a64-48dd-9951-e65bf8367cd0%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> Hello,
>>
>> Thanks and Warm Regards
>> ---
>> HaatBhaar Team | +91-906-708-0040
>> --
>> Sabka *HaatBhaar*, Sabka *Udhaar*!
>>
> --
> 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/ba80e00a-0ea1-4bae-bb15-3f98c39a8f77%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/CABF8kZPgyEYWoiUctaCTRyZsjuH5NAOgtdY6Lw-6L6Jp2APp%3Dg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best way to add an image from a filefield to django 2.0 admin?

2018-06-06 Thread Daniel Germano Travieso
Hello Mark.

You can just override the Model Admin for your model and insert an Inline
Form for example.

Check the documentation for customizing the model admin!

Hope it helps!


On Mon, Jun 4, 2018, 18:02 Mark Phillips  wrote:

> I have a Document model that uploads an image. I have a DocumentMetaData
> model with a JSON field where I "crud" metadata for the documents in the
> Document model.
>
> I would like to add the image of the document in the Document model to the
> change form of the DocumentMetaData model in the admin. How do I do it? Do
> I have to override the admin/change_form.html for the DocumentMetaData
> model?
>
> Thanks!
>
> Mark
>
> --
> 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/CAEqej2PYNudeSWa5CY934m8kMWO%3Dhcpj4%3DxQud9C-wZCHoaS4g%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/CABF8kZOWiPDeDrtTbuytOD8Nm%3DHqd1A%2BtwNKSkmmEyk85jVGzA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: calculate the followers difference/grow by day

2018-06-04 Thread Daniel Germano Travieso
Hello!
I don't quite understand what you mean by the followers difference by day,
but as that difference by day is not a property of each model tuple, but a
property of a specific day, you can write a view to handle that processing.
Custom model Managers are used to either add manager methods or to
customize and change the QuerySet your model returns. If you wish to use
the model manager for this, it could be used to add a field to your model
that makes a query to the last followers on that day and calculates the
difference (?). You could also use a @property on your Model class for that
too.

Hope it helps!

*[]'s*
*Daniel Germano Travieso*
*Engenharia da Computação Turma: 013*
*Unicamp*

On Thu, May 31, 2018 at 11:14 AM, João Paulo 
wrote:

>
> Hey guys,
>
> I´m using SQLite and trying to calculate the followers difference by day
>
> This is my model:
>
> class Statistics(models.Model):
> followers = models.IntegerField()
> last_update = models.DateTimeField(auto_now_add=True)
>
> This are my database rows:
>
> "6" "50" "*2018-05-29* 00:25:48.276102"
> "1" "100" "*2018-05-29* 00:26:48.276102"
> "3" "200" "*2018-05-30* 00:27:04.178444"
> "5" "250" "*2018-05-30* 00:30:04.178444"
> "4" "300" "*2018-05-31* 00:27:04.178444"
>
> And the result I´m tryting to achieve is:
>
> followers | last_update
> 150
> *2018-05-30*50
>
> *2018-05-31*
> *# I´m new to Django and thinking about use a Manager, but don't know if´s
> doable using a Manager# Does anyone has a suggestion ?*
>
> --
> 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/3196a628-a53f-41ac-bcbf-6cc8b8a66016%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/3196a628-a53f-41ac-bcbf-6cc8b8a66016%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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/CABF8kZNYHY8zWYNw3WKTxLMcnsxxDU9hPAep4wpzk9i4c-veRg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: installation help please

2018-06-04 Thread Daniel Germano Travieso
If you are using Windows, I highly recommend you to use a tool such as
Conda or VirtualEnv. It greatly increases the level of encapsulation of
your different django projects you may create, as each one may use
different python or django modules.

Check Conda out at https://anaconda.org/anaconda/conda

Hope it helps.

*[]'s*
*Daniel Germano Travieso*
*Engenharia da Computação Turma: 013*
*Unicamp*

On Thu, May 31, 2018 at 8:24 AM, Rafael E. Ferrero  wrote:

> please use some kind of virtual environment... in linux its virtualenvs
>
>
> Rafael E. Ferrero
>
> 2018-05-31 8:06 GMT-03:00 kailash jangu :
>
>> guys i installed django version 2.0.5 in windows but when i use
>> django-admin command it shows me error what path i should i go with to get
>> start with my newproject and do database api driver has role in it. i have
>> my django-admin executive and python file in pyhton36/scripts what do i do
>> help please...
>>
>> --
>> 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/ms
>> gid/django-users/139a9b30-7301-4ac9-a0af-816621fda116%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/139a9b30-7301-4ac9-a0af-816621fda116%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> 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/CAJJc_8XS%2BdX_sTQUXQcLPrDSFaszLzhoAqayWHZF0A
> x2bp4ptQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAJJc_8XS%2BdX_sTQUXQcLPrDSFaszLzhoAqayWHZF0Ax2bp4ptQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> 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/CABF8kZP7ZsSqb67ZK0iFJiXoNUe4%3DGV1zdpdJb5v7bCe5E7xAg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multisite strategy

2018-06-04 Thread Daniel Germano Travieso
Hello Carlo,

I don't see what you mean by change the current site at runtime?

If you mean change the site the user is accessing, just forward the user
via the URL to the proper site you mean to reach.

Hope it helps!

*[]'s*
*Daniel Germano Travieso*
*Engenharia da Computação Turma: 013*
*Unicamp*

On Thu, May 31, 2018 at 5:14 AM, Carlo Ascani  wrote:

> Il giorno mer 23 mag 2018 alle ore 17:02 Daniel Germano Travieso
>  ha scritto:
> >
> > Hello!
> > The Sites Framework is exactly what you need (and the proper
> internationalization/localization for the languages).
> > Just set up your 3 sites the Django way (creating the propper
> settings.py for each site)
> > Then you can run each site using `manage.py runserver  --settings
> .py`
> >
> > You can access each different site in development by going to
> localhost:
> >
> > As a suggestion, to avoid overhead in the creation of a site that is
> only responsible for the choice of the site and language, I would assing
> one of the two sites to be the default one, but the first action the user
> takes when accessing the site is to choose location and language, but it is
> a personal thing and your way can and will work fine!
> >
> > Hope it helps!
>
>
> Thank you!
>
> Is it possible to change the current site at runtime?
>
>
> >
> > []'s
> > Daniel Germano Travieso
> > Engenharia da Computação Turma: 013
> > Unicamp
> >
> > On Tue, May 22, 2018 at 3:31 AM, Carlo Ascani 
> wrote:
> >>
> >> Hi all,
> >>
> >> I'd like to implement something like this:
> >>
> >> One Django project to serve 3 sites:
> >> 1. `domain.com` which is the "master" site, containing just a landing
> page
> >> 2. `de.domain.com` which is the "German" site
> >> 3. `en.domain.com` which is the "UK" site
> >>
> >> `de` and `en` refers the location, not the language (e.g. `
> de.domain.com/en/` is the German site in English)
> >>
> >> If you go to `domain.com` you can choose the language and the country,
> and you are just redirected to the right place.
> >>
> >> Is `contrib.site` suitable for that scenario?
> >> I was thinking at 3 different sites.
> >> If so, how can I use them locally while in development?
> >>
> >> Any other suggestions?
> >>
> >> Best,
> >> Carlo
> >>
> >>
> >> --
> >> 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/3b068855-78e7-4742-890d-1fc8a545b4f4%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/CABF8kZM%2BD-4Cou6s0bHJC15MeXLjeEaVrLBLdDTH
> d5%3DG1%3DupPA%40mail.gmail.com.
> > For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> Carlo Ascani aka carloratm
>
> http://carlo.ratm.gitlab.io
> carloratm@freenode
>
> --
> 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/CABVJJr8ONoKEWyYa-_43JMb%3DhnzRa_d6JzNfK29G58SkiwJQAw%
> 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/CABF8kZOkeN_JbOtWiRYTK%3DpiP%3D_hzvAj9bdDaW2-V5NoF-_Eyg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django attempting to connect to mysql without password even when password has been provided

2018-05-27 Thread Daniel Germano Travieso
Hello! What version of Django are you running?

You may need to provide extra info such as host and port

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'mydatabase',
'USER': 'mydatabaseuser',
'PASSWORD': 'mypassword',
    'HOST': '127.0.0.1',
'PORT': '5432',
}}

Hope it helps



*[]'s*
*Daniel Germano Travieso*
*Engenharia da Computação Turma: 013*
*Unicamp*

On Sun, May 27, 2018 at 8:24 AM, Coder Dude  wrote:

> This is the code in my settings.py :
>
> import pymysql
>
> pymysql.install_as_MySQLdb()
>
>
> DATABASES = {
> 'default': {
> 'ENGINE': 'django.db.backends.mysql',
> 'NAME': 'learn001',
> 'USER': 'test01',
> 'PASSWORD': 'test01', #Password is also test01
>
>
> }
> }
>
>
> Yet , it is throwing the following error :
>
> django.db.utils.OperationalError: (1045, "Access denied for user 
> 'test01'@'localhost'
> (using password: NO)".
>
> I don't understand why it is trying to connect without a password.
>
> It works properly if I create a user with no password and then provide
> it's username.
>
>
>
>
> --
> 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/bc025b3b-58b6-450a-8d37-3fca71568e72%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/bc025b3b-58b6-450a-8d37-3fca71568e72%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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/CABF8kZPSeDL3fy5p29cdrSD2dNe%3D0q8Q1P6ATbHXNtJzg1imxw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: geodjango wrong srid when it saves feature

2018-05-23 Thread Daniel Germano Travieso
Hello!

You should probably use the LineString from django.contrib.gis.geos to
store Geo objects on the database

Hope it helps.

*[]'s*
*Daniel Germano Travieso*
*Engenharia da Computação Turma: 013*
*Unicamp*

On Wed, May 23, 2018 at 11:54 AM, Majid Hojati  wrote:

> Hi,
> I tried to read data from a shape file and save them into database. well
> here is my code
>
>
> lyr = ds[0]
>
> for feat in lyr:
> geom_t = feat.geom.transform(wgs84, clone=True)
> print(geom_t.wkt)
> print(feat.geom.wkt)
>
> name =''
> Twoway='1'
>
> data = {
> 'name': name,
> 'Twoway': Twoway,
> 'geom': geom_t.wkb
> }
> form = Street_Form(data)
> if form.is_valid():
> savedlocation = form.save()
>
>
> well it saves and works fine. I printed some of my geometries as wkt before 
> saving to databse and here is the result
>
>
> LINESTRING (50.9847540637495 35.8384680697353,50.9850968571006 
> 35.8383655346687)
> LINESTRING (50.9847540637495 35.8384680697353,50.9850968571006 
> 35.8383655346687)
>
>
> As you can see they are EPSG:4326 and nothing is wrong.
> Here is my model
>
> class str(models.Model):
> geom = models.LineStringField(srid=4326)
>
>
> but when I read data from database they are as following
>
>
> "LINESTRING(0.000457917485762628 0.000321907544087987,0.000457920236524686 
> 0.000321915031075541)"
>
>
> the above result is from this query
>
>
> select st_astext(geom) from public."app_str"
>
>
> well the geometries are misplaced, where is the problem?why this happens?
>
> --
> 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/76979930-39f5-4deb-9c95-dcf3d7f55f97%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/76979930-39f5-4deb-9c95-dcf3d7f55f97%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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/CABF8kZPV%2Bn4ebw7hh%2BvfcacsbWsDUt4oS2XW6NJuf91tQYNoQA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Issue with Django migrate - fine with 2.7x python, but error with 3.6.4?

2018-05-23 Thread Daniel Germano Travieso
As Melvyn statet, I do not believe this is a py2 vs py3 issue.

On your stacktrace it seems as the migrations of the quickbbs app are
conflicting in some way.

Maybe a migration was created using py2 and another using py3 (as they were
created 6 months appart - the name of the migration is a timestamp). Take a
look at each migration file to analyse what it is doing. And if possible,
you can try to merge manually what the migrations are doing and leave only
one of them to be run.

Another issue could be VCS related, and some migration file was
added/ignored on the filesystem making the migrations fail.

To test everything, you can backup you DB somewhere and make the migrations
again from scratch.

Hope it helps!

*[]'s*
*Daniel Germano Travieso*
*Engenharia da Computação Turma: 013*
*Unicamp*

On Wed, May 23, 2018 at 10:56 AM, Melvyn Sopacua 
wrote:

> On woensdag 23 mei 2018 12:55:58 CEST Benjamin Schollnick wrote:
>
> > nerv:quickbbs Benjamin$ manage.py migrate --run-syncdb
>
> 
>
>
> > (quickbbs) nerv:quickbbs Benjamin$ python3 manage.py migrate
> >
> > Running on nerv.local
> >
> > CommandError: Conflicting migrations detected; multiple leaf nodes in the
> > migration graph: (0019_auto_20171108_0155, 0044_auto_20180519_1914 in
> > quickbbs).
>
> Not convinced yet this is a py2 versus py3 problem. First, you're running
> different command flags (though, not sure it matters in this case).
> Second, the
> Django version for py3 can be different from the py2 version.
>
> From the backtrace it isn't clear though which app is causing this. If it
> really is a py2 versus py3 issue, then I suspect that some migrations are
> done
> only for py3, though that is really bad practice.
>
> --
> Melvyn Sopacua
>
> --
> 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/2403869.zZKC4CeI1l%40fritzbook.
> 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/CABF8kZP5MT%2BCedZ7xun7rzAt2ot%2BCg1SmG5LXaE_BFti1367fQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Multisite strategy

2018-05-23 Thread Daniel Germano Travieso
Hello!
The Sites Framework is exactly what you need (and the proper
internationalization/localization for the languages).
Just set up your 3 sites the Django way (creating the propper settings.py
for each site)
Then you can run each site using `manage.py runserver  --settings
.py`

You can access each different site in development by going to
localhost:

As a suggestion, to avoid overhead in the creation of a site that is only
responsible for the choice of the site and language, I would assing one of
the two sites to be the default one, but the first action the user takes
when accessing the site is to choose location and language, but it is a
personal thing and your way can and will work fine!

Hope it helps!

*[]'s*
*Daniel Germano Travieso*
*Engenharia da Computação Turma: 013*
*Unicamp*

On Tue, May 22, 2018 at 3:31 AM, Carlo Ascani  wrote:

> Hi all,
>
> I'd like to implement something like this:
>
> One Django project to serve 3 sites:
> 1. `domain.com` which is the "master" site, containing just a landing page
> 2. `de.domain.com` which is the "German" site
> 3. `en.domain.com` which is the "UK" site
>
> `de` and `en` refers the location, not the language (e.g. `
> de.domain.com/en/` <http://de.domain.com/en/> is the German site in
> English)
>
> If you go to `domain.com` you can choose the language and the country,
> and you are just redirected to the right place.
>
> Is `contrib.site` suitable for that scenario?
> I was thinking at 3 different sites.
> If so, how can I use them locally while in development?
>
> Any other suggestions?
>
> Best,
> Carlo
>
>
> --
> 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/3b068855-78e7-4742-890d-1fc8a545b4f4%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/3b068855-78e7-4742-890d-1fc8a545b4f4%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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/CABF8kZM%2BD-4Cou6s0bHJC15MeXLjeEaVrLBLdDTHd5%3DG1%3DupPA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Insert data into multiple models when doing POST method

2018-05-21 Thread Daniel Germano Travieso
Hello!

​As my initial understanding, you are attempting to use some sort of Django
REST Framework.
Check the django-rest-framework documentation for some insights:
http://www.django-rest-framework.org/api-guide/serializers/

You will need to overwrite the .create method of the Patient Model and the
.create method of the Serializer.

Hope it helps!​


*[]'s*
*Daniel Germano Travieso*
*Engenharia da Computação Turma: 013*
*Unicamp*

On Mon, May 21, 2018 at 12:59 PM, thiagarajan.kpt  wrote:

> Hi,
>
> I have two models (Patients and PatientAddress). I want to create a new
> patient using POST method and data should be inserted in Patient and
> PatientAddress tables. But the data is inserted only into Patients table
> and not in PatientAddress table.
>
> When I POST a new patient with Address then automatically it should create
> a new record in PatientAddress table with patnt_refno referencing to the
> Patient table. *Could someone please assist to proceed further.*
>
> Below is my code.
>
> *POST Input:*
> {
> "Address": [
> {
> "line": "3A insert Second Street",
> "city": "insert city",
> "country": "India"
> }
> ],
> "patnt_id": "P14",
> "surname": "Smith",
> "forename": "James",
> "gender": "M",
> "active": 1
> }
>
>
> *models.py*
> class Patients(models.Model):
> patnt_refno = models.AutoField(primary_key=True)
> patnt_id = models.CharField(unique=True, max_length=10, blank=True,
> null=True)
> surname = models.CharField(max_length=30, blank=True, null=True)
> forename = models.CharField(max_length=50, blank=True, null=True)
> gender = models.CharField(max_length=1, blank=True, null=True)
> dttm_of_birth = models.DateTimeField(blank=True, null=True)
> dttm_of_death = models.DateTimeField(blank=True, null=True)
> marital_status = models.CharField(max_length=50, blank=True,
> null=True)
> active = models.IntegerField()
>
> def __str__(self):
> return self.patnt_id
>
> class Meta:
> managed = False
> db_table = 'patients'
>
> class PatientAddress(models.Model):
> addss_refno = models.AutoField(primary_key=True)
> patnt_refno = models.ForeignKey('Patients', db_column='patnt_refno',
> related_name='Address')
> line = models.CharField(max_length=30, blank=True, null=True)
> city = models.CharField(max_length=50, blank=True, null=True)
> state = models.CharField(max_length=50, blank=True, null=True)
> country = models.CharField(max_length=50, blank=True, null=True)
> postcode = models.CharField(max_length=50, blank=True, null=True)
> active = models.IntegerField(blank=True, null=True)
>
> class Meta:
> managed = False
> db_table = 'patientaddress'
>
>
> *serializers.py*
> class PatientAddressSerializer(serializers.ModelSerializer):
>
> class Meta:
> model = PatientAddress
> fields = ('line','city','country')
>
> class PatientsSerializer(serializers.ModelSerializer):
> Address = PatientAddressSerializer(read_only=True,many=True)
>
> class Meta:
> model = Patients
> fields = ('Address','patnt_refno','patnt_id','surname','forename'
> ,'gender','active')
>
>
> *views.py*
> class PatientsList(APIView):
>
> def get(self, request):
> patients = Patients.objects.filter(gender='M',active=1).order_by(
> 'dttm_of_birth').reverse()
> serializer = PatientsSerializer(patients, many=True)
> return Response(serializer.data)
>
> def post(self, request):
> serializer = PatientsSerializer(data=request.data)
> if serializer.is_valid():
> serializer.save()
> return Response(serializer.data, status=status.HTTP_201_
> CREATED)
> return Response(serializer.errors, status=status.HTTP_400_BAD_
> REQUEST)
>
> *urls.py*
> urlpatterns = [
> url(r'^admin/', admin.site.urls),
> url(r'^patients/$', views.PatientsList.as_view()),
> ]
>
>
>
> Thanks in advance,
> Thiagu Palaniappan
>
> --
> 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
&

Re: First View

2018-05-21 Thread Daniel Germano Travieso
Hello!

As you configured, the available url patterns you have on your project are:
"/admin/" and "/boutique/"... And as you request
states, you are trying to access the path "/".. So django didn't
find any matching url pattern for that.

To access the view you are intended to access, you should access
"/boutique/".

To advance further I recommend you to check the documentation on URL
patterns!

Hope it helps.

*[]'s*
*Daniel Germano Travieso*
*Engenharia da Computação Turma: 013*
*Unicamp*

On Mon, May 21, 2018 at 5:55 PM, Tristan Demot 
wrote:

> Hello,
>
> I use tutorial 1.11
>
> beaumarche (startproject)
>
> from django.conf.urls import include, url
> from django.contrib import admin
>
>
> urlpatterns = [
>
> url(r'^boutique/', include('boutique.urls')) ,
> url(r'^admin/', admin.site.urls),
> ]
>
>
> boutique (app)
>
>
> urls.py
>
>
> from django.conf.urls import url
>
>
> from . import views
>
>
> urlpatterns = [
>   url(r'^$', views.index, name='index'),
> ]
>
>
>
>
> views.py
> from django.http import HttpResponse
>
>
> def index(request):
>  return HttpResponse ("Hello, world...")
>
>
> 127.0.0.1:8000
> Using the URLconf defined in beaumarche.urls, Django tried these URL
> patterns, in this order:
>
>
> 1.^boutique/
> 2^admin/
>
>
> The empty path didn't match any of these
>
> An idea maybe
>
> 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/5431a0c8-1365-4a73-8026-25c57c2f775b%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/5431a0c8-1365-4a73-8026-25c57c2f775b%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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/CABF8kZPpN_nQ1Xkjq-5%2BWBip1EMxtY-sUuo9grZ4ZnttL5hRag%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Temporal table in Django 1.6

2018-05-21 Thread Daniel Germano Travieso
Hello!

First of all, I highly recommend you to use django* 1.8 or upper*, as de
1.6 version is* no longer supported* by the official django development.
After that note, as you can see, the database engine backends that come
bundled with Django are as follows (
https://docs.djangoproject.com/en/2.0/ref/settings/#engine )

- 'django.db.backends.postgresql'
- 'django.db.backends.mysql'
- 'django.db.backends.sqlite3'
- 'django.db.backends.oracle'

But as stated on the same page, you can create your own backend (one that
supports Temporal Tables on another DBMS - suche as MS SQL Server 2016) and
bundle it with your app. To see the appropriate documentation for the
databases api for you to create the backend, just go to the appropriate
section ( https://docs.djangoproject.com/en/2.0/ref/databases/ ).

Another option is for you to find an app available somewhere out there on
the internet that provides a backend with Temporal Tables.

Hope it helps!

*[]'s*
*Daniel Germano Travieso*
*Engenharia da Computação Turma: 013*
*Unicamp*

On Mon, May 21, 2018 at 4:13 PM, Nirali Supe 
wrote:

> Hello,
>
> I need to create Temporal table in Django 1.6
> Does Django support  Temporal table model? I unable to find the Django
> documentation on it.
> Can someone please point me to the documentation?
>
> Thank you,
> Nirali Supe
>
> --
> 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/918a65bb-e9c3-42fb-9170-6e5092b62bc5%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/918a65bb-e9c3-42fb-9170-6e5092b62bc5%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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/CABF8kZODAepLqyEoFhM7%2BWww4FGO7zskJrOyt37rhAgdqBUb6w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to create receipt forms using django.

2018-05-21 Thread Daniel Germano Travieso
Hello

Dwelve into the official Django Tutorial and learn it's basic, then go on 
to trying to create the app you want!

https://docs.djangoproject.com/en/2.0/intro/tutorial01/

Hope it helps.

On Monday, May 21, 2018 at 4:20:37 AM UTC-3, subhani shaik wrote:
>
> Hi group numbers...
>
> How to create supermarket receipt forms using django& python with the help 
> of HTML.please give me that code.plz..
>
>
>
>
>
> Thanks.
> subhani shaik
>

-- 
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/778f828f-4bae-4ae0-8738-31d676942588%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how to import functions of app from the same project from other app

2018-05-21 Thread Daniel Germano Travieso
Hello Asif!

To use a method from one app in another app would require you to import the 
app's module (using from - import statements), allowing the interpreter to 
know that the function from one scope is available on another.

In a serious note, I recommend that you first familiarize yourself with the 
Python language, maybe take a online course/tutorial about all its 
functionalities, and then go on to learning Django (maybe take the Django 
Documentation tutorial, it is really good).

I will leave you here some links to good resources for both beginner and 
advanced python and django.

https://learnpythonthehardway.org/book/
https://docs.python.org/3/tutorial/index.html
https://developers.google.com/edu/python/

https://docs.djangoproject.com/en/2.0/intro/tutorial01/
https://docs.djangoproject.com/en/2.0/

Hope it helps!

On Monday, May 21, 2018 at 2:01:45 PM UTC-3, Asif Khan wrote:
>
> I am trying to import function wrote in one of app in a project to import 
> that function in other app in same project.
>
> like I have one project and two apps.
>
> Project1
>Project1
>accounts app (function written in this app)
>VV app (wants to utilize in this app)
>
> I am new to Python and Django as developer.
>
> Regards, Asif
>   
>
>

-- 
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/17ff2816-73db-431f-a1c4-bcf0a7417eca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: SMTPRecipientsRefused: Sender address rejected: not owned by user

2018-05-19 Thread Daniel Germano Travieso
The problem you are having is described by the error message.

The email  you are using and configured on the 
settings.py to be the DEFAULT_FROM_EMAIL is not being recognized by the 
email server. Maybe you lack the configuration of that email address on the 
email provider?

Either way, on the DEFAULT_FROM_EMAIL you should put a email that your 
email provider recognizes. If you want, you can use the reply_to attribute 
so the replies are sent to  after the email you have 
 sent the email.

Hope it helps!

On Tuesday, May 15, 2018 at 9:38:48 PM UTC-3, Tom Tanner wrote:
>
> I have a Django app running on a server with uWSGI and nginx. 
>
> In my `local_settings.py` file I have this:
>
> ###
> # EMAIL SETUP #
> ###
> EMAIL_HOST = 'smtp.privateemail.com'
> EMAIL_HOST_USER = 'sup...@mydomain.com '
> EMAIL_HOST_PASSWORD = 'MY EMAIL PASSWORD'
> EMAIL_PORT = 465
> EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
> EMAIL_USE_TLS = True
> 
> 
> 
> # OTHER EMAIL SETTINGS #
> 
> ADMIN_EMAIL = "ad...@mydomain.com "
> SUPPORT_EMAIL = "sup...@mydomain.com "
> DEFAULT_FROM_EMAIL = ADMIN_EMAIL
> SERVER_EMAIL = ADMIN_EMAIL
>
> I run `python manage.py runserver` on my local machine in the Django 
> project's virtual environment. I fill out the password reset form at 
> `password_rest/` using the email `my.pe...@gmail.com ` and 
> submit it. I get this error.
>
> SMTPRecipientsRefused: {u'my.p...@gmail.com ': (553, 
> '5.7.1 >: Sender address rejected: not 
> owned by user sup...@mydomain.com ')}
>
> My website's email provider is Namecheap.
>
> Why do I get this error when testing on my local machine? What must I 
> change/add to get rid of it?
>

-- 
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/9368f733-dec3-4be0-b946-6a883be041e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Managing multiple user types in Django

2018-05-19 Thread Daniel Germano Travieso
There is no really definitive approach to handle this, and you could do it 
either way. 
Either option works, but for a philosofical point of view, if there is no 
significant difference between the user types, the first approach I tend to 
believe is the most logical one.

However, as a optimal approach, to think on all possible overheads you may 
encounter on your system, I believe the second option is best, as it 
isolates authentication methods to a specific and stablished module 
provided by django, avoiding you the hassle of maybe having to override 
user-specific methods.

On my projects I tend to lean towards User + Profile approach.

On the point of view of performance, the User + Profile approach has de 
disadvantage of requireing a database join in order to retrieve 
user-specific information.

The official django doc has a view on this very subject

https://docs.djangoproject.com/en/2.0/topics/auth/customizing/#specifying-a-custom-user-model
 
:

" *Model design considerations*

Think carefully before handling information not directly related to 
authentication in your custom user model.

It may be better to store app-specific user information in a model that has 
a relation with the user model. That allows each app to specify its own 
user data requirements without risking conflicts with other apps. On the 
other hand, queries to retrieve this related information will involve a 
database join, which may have an effect on performance."


Hope it helps!

On Wednesday, May 16, 2018 at 11:53:58 AM UTC-3, Bill Torcaso wrote:
>
>
> I inherited a system which has one User model, and a Profile model that is 
> 1-to-1 with User.  The type-of-user information is carried in a required 
> "role" property in the Profile.  I think that is a well-established 
> approach.
>
> I am curious to hear what people think of the tradeoffs between (User + 
> Profile) and (User-base-class + subclasses).
>
> On Tuesday, May 15, 2018 at 12:41:50 PM UTC-4, Vijay Khemlani wrote:
>>
>> I would make a UserType table and have a foreign key from your user model 
>> to it, or maybe just have an enumerated type in your user model depending 
>> on how much custom logic there is to each user type.
>>
>> On Tue, May 15, 2018 at 11:50 AM Frankline  wrote:
>>
>>> Hello Everyone,
>>>
>>> I am developing an API based on Django Rest Framework 
>>> . Currently I have 4 user types 
>>> i.e. Buyer, Merchant, Insurer, and Admin.
>>>
>>> The system I'm developing has an *API endpoint* and a *Dashboard* view.
>>>
>>> Each of the above user types have different fields and may need to login 
>>> to the system at one point, so having one user model is the best way to go. 
>>> Note that, a user can only be of one type.
>>>
>>> However, only the merchant will be actively using the API endpoint.
>>>
>>> My question is then, how will I be able to manage the different user 
>>> types in the system?
>>>
>>> My current options are:
>>>
>>> 1.
>>>
>>>1. class BaseUser(AbstractBaseUser):
>>>2. ...
>>>3.  
>>>4. class Buyer(BaseUser):
>>>5. ...
>>>6. 
>>>
>>>
>>>1. class Merchant(BaseUser):
>>>2. ...
>>>3. 
>>>
>>>
>>>1. class Insurer(BaseUser):
>>>2. ...
>>>
>>>
>>> 2. 
>>>
>>>
>>>1. from django.db import models
>>>2. from django.contrib.auth.models import User
>>>3.  
>>>4. class Buyer(models.Model):
>>>5. user = models.OneToOneField(User)
>>>6.  
>>>7. class Merchant(models.Model):
>>>8. user = models.OneToOneField(User)
>>>9. 
>>>
>>>
>>>1. class Insurer(models.Model):
>>>2. user = models.OneToOneField(User)
>>>
>>>
>>>
>>>1. ...
>>>
>>>
>>> Which is the most optimal way of handling this?
>>>
>>>1. 
>>>
>>>
>>>
>>>
>>> -- 
>>> 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...@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/CAEAUGdVwB_RrOP_s9Oj5fe6AoOXJ9qpPLUKpE%2BbAO_NLGMRn6g%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.goo

Re: whats the use of setting mysite.settings to DJANGO_SETTINGS_MODULE?

2018-05-19 Thread Daniel Germano Travieso
This is done so that when you run the script manage.py (that runs django 
commands) the module django imported by the script knows which project 
settings to use.

If you do not provide this, django will not recognize the apps you are 
developing, and will just recognize the default apps it comes bundled with.

https://docs.djangoproject.com/en/1.11/topics/settings/#envvar-DJANGO_SETTINGS_MODULE

On Thursday, May 17, 2018 at 12:09:33 AM UTC-3, Utpal Brahma wrote:
>
> under manage.py
>
>
> 
>
>
> #!/usr/bin/env python
> import os
> import sys
>
> if __name__ == "__main__":
> os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
> try:
> from django.core.management import execute_from_command_line
> except ImportError:
> # The above import may fail for some other reason. Ensure that the
> # issue is really that Django is missing to avoid masking other
> # exceptions on Python 2.
> try:
> import django
> except ImportError:
> raise ImportError(
> "Couldn't import Django. Are you sure it's installed and "
> "available on your PYTHONPATH environment variable? Did 
> you "
> "forget to activate a virtual environment?"
> )
> raise
> execute_from_command_line(sys.argv)
>
>
>
>

-- 
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/fe7f1f18-69d5-49e8-ac67-593e6914fa63%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django ModelAdmin ignores has_delete_permission

2018-05-19 Thread Daniel Germano Travieso
Hello!

Ordinary staff users on the main django admin module are just standard 
django users that can access the admin site.

Setting the has_add_permission, has_change_permission and 
has_delete_permission via the ModelAdmin should be done to customize the 
permissions for specific object instances (as stated on the documentation 
https://docs.djangoproject.com/en/1.11/topics/auth/default/#topic-authorization 
)

The propper way to set the default permissions for a ordinary staff user 
should be either by assigning user/group permissions via 
- the superuser user on the admin site 
- via command line using the myuser.user_permissions.set([permission_list]) 
or myuser.user_permissions.add() or .remove() or using 
myuser.groups.set([group_list]) and myuser.groups.add(group1, group2) / 
.remove(group1, group2).
- programatically on specific staff user creation, using the same methods 
as the above

Either option should give the staff user the propper permissions to a 
specific model. The default permissions for a specific model always are 
named, for a app with app_label foo, as follows: foo.add_bar, 
foo.change_bar and foo.delete_bar where bar is the lowercase name for the 
specific model.

I encourage you to read on the Official Django Documentation for the topic 
of authorization as it provides these and other insights.

Hope it helps!

On Friday, May 18, 2018 at 4:36:07 AM UTC-3, Vitaly Trifanov wrote:
>
> I have simple project on Django 1.11.13, that uses ordinary Django's admin 
> module. Staff user can not delete object while is permitted 
> (has_delete_permission returns always true).
>
> models.py:
>
>
> class MyModel(models.Model):
> name = models.IntegerField("Value", blank=True, null=True)
>
> admin.py:
>
>
> @admin.register(MyModel)class MyModelAdmin(admin.ModelAdmin):
> def has_add_permission(self, request):
> return True
>
> def has_change_permission(self, request, obj=None):
> return True
>
> def has_delete_permission(self, request, obj=None):
> return True
>
>
> I created user and logged in. He can create MyModel object (as expected), 
> can edit (as expected), but can not delete!!
>
> That's what I see if I try to delete it:
>
> Deleting the selected my model would result in deleting related objects, 
> but your account doesn't have permission to delete the following types of 
> objects:
>
> my model
>
> What am I doing wrong? How should I give permissions to delete MyModels to 
> ordinary staff user?
>

-- 
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/35bafb48-34c8-418a-9f70-10dbb6f54868%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Please I need help on how to create a custom method for a model with list_display

2018-05-19 Thread Daniel Germano Travieso
Hello!

On your case, as stated on the official doc, you should just create a 
method on the model you want to display the ManyToMany field on the 
list_display that maybe returns the list of items from the ManyToMany 
field. Django avoids using this as it could be a potential overhead as you 
will run seperate queries on the database to fetch all the related 
many-to-many objects.

But if you are feeling adventurous, just create the method that performs 
that query.

i.e. On your Book model you create a method that returns the 
self.authors.all() set. Then you use that method's name on the list_display 
instead of authors.

Hope it helps.

On Saturday, May 19, 2018 at 3:54:17 PM UTC-3, Godson Rapture wrote:
>
> Please I am learning Django 2.0.4
>
>
> Right now I am learning about Django Admin.
>
>
> I got an error that the value of my list_display should not be a 
> ManyToMany Field.
>
>
> I referred back to Django official doc and I was asked to create a custom 
> method for my model.
>
>
> I tried looking for an example of how to do that, I could not see.
>
>
> Here is my model.py program
>
>  from django.db import models
>
> class Publisher(models.Model):
> name = models.CharField(max_length=30)
> address = models.CharField(max_length=50,blank=True)
> city = models.CharField(max_length=60,blank=True)
> country = models.CharField(max_length=50,blank=True)
> website = models.URLField()
> def __str__(self):
> return self.name
>
> class Author(models.Model):
> salution = models.CharField(max_length=10)
> first_name = models.CharField(max_length=30)
> last_name = models.CharField(max_length=40)
> email = models.EmailField()
> headshot = models.ImageField(upload_to = "tmp")
> def __str__(self):
> return f"{self.first_name} {self.last_name}"
>
> class Book(models.Model):
> title = models.CharField(max_length=100)
> authors = models.ManyToManyField(Author)
> publisher = models.ForeignKey(Publisher,on_delete=models.CASCADE,)
> publication_date = models.DateField()
> def __str__(self):
> return self.title
>
> Here is my admin.py program
>
> from django.contrib import admin
> from polls.models import Book, Publisher, Author
> # Register your models here.
>
> class BookAdmin(admin.ModelAdmin):
> list_display = [
> "title",
> "authors", #a ManyToMany Field
>
> ]
>  search_fields = [
> "Book"
> ]
> class Meta:
> model = Book
>
> admin.site.register(Book, BookAdmin)
>
> Can someone please help me.
>
> 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/56c58fb6-7074-47aa-9536-8d8027ef70a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How do you deal with two third party apps with the same App label?

2018-05-19 Thread Daniel Germano Travieso
Hello!

As seen here on the documentation for Applications configuration for app 
users, you can provide a custom app configuration for one of the third 
party apps you are using on your project.

https://docs.djangoproject.com/en/2.0/ref/applications/#for-application-users

I believe this would solve the ImproperlyConfigured exception as on your 
settings.py on your INSTALLED_APPS you would have the apps with different 
names.
Hope it helps!

On Saturday, May 19, 2018 at 10:54:02 PM UTC-3, Mario R. Osorio wrote:
>
> Hello everyone,
>
> In  Django 2.0.5; I want to use python-twitter and allauth's twitter 
> provider and both these apps use the same App label which results in  the 
> *django.core.exceptions.ImproperlyConfigured: 
> Application labels aren't unique* error
>
> I have searched the internet and found no solutions to this Issue and 
> would really appreciate your input on this matter.
>
> Any and all comments and ideas are welcome.
>
>
> TIA!
>
>

-- 
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/30ba1abc-2c11-4a19-af74-f706e506871e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.