Re: Disabling Django Admin, and creating my own three custom admin dashboards

2019-11-10 Thread Wim Olivier
Great, thanks man!
I will try that.
Using local auth and PostgreSQL - no cloud services.

Regards!
Wim

On Mon, 11 Nov 2019 at 08:39, Motaz Hejaze  wrote:

> I dont know what is your authentication based on , but i faced such a
> scenario ..
>
> One of the solutions is to make a middleware that checks the user type
> with the url prefix
>
> So usertype1 all related routes will be under /usertype1/
>
> usertype2 all related routes will be under /usertype2/
>
> Middleware will check user_type fron sessions or jwt ( depends on your
> auth system ) and compare it with the requested url , if they are identical
> then permission guaranteed , else redirect somewhere
> On Mon, 11 Nov 2019, 8:14 am Wim Olivier,  wrote:
>
>> Thanks Motaz,
>>
>> That gives me a little bit of direction.
>> I'm thinking now of controlling access to each app's URL's via a single
>> piece of middleware (instead of at each View - just have to figure out how
>> to do that.
>>
>> Regards,
>> Wim
>>
>> On Saturday, 9 November 2019 10:44:58 UTC+2, Motaz Hejaze wrote:
>>>
>>> If you dont want django admin just remove it from installed apps ,
>>> middleware and urls..
>>>
>>> But i dont advice you to do this , you can make you own dashboards and
>>> keep django default admin panel ..
>>>
>>> You need a 3 signup pages and 3 login pages , each signup page will
>>> create a different user and each login page will login each user type to
>>> his dashboard type ..
>>>  I advice you to make a 3 seperate apps to organize the code ..
>>>
>>> On Sat, 9 Nov 2019, 5:34 am Wim Olivier,  wrote:
>>>
 Hi everyone,

 I would like to disable the Django Admin, and create my own custom
 admin dashboards.
 There must be three different types of admin dashboards:
 - one for Customers (normal users) where they can do CRUD on their
 profile and services (URI: /customer/dashboard)
 - one for Partners where they can do CRUD on their users/customers, and
 their Customers' profile and services (URI: /partner/dashboard)
 - one for Super Users where they can do CRUD on Customers, Partners,
 and everything else (URI: /administration)

 I understand very well the ways to extend the User model - that part
 I'm OK with.

 Just some practical pointers with a small example, or links to
 Django-based repos that implement something like this, please.
 I just need some guidance.

 Many thanks!
 Wim Olivier
 South Africa

 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to django...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/66befa62-2c5b-4d3d-9653-1c8169ccdcc2%40googlegroups.com
 
 .

>>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/8b2bcb0b-803c-4da2-9d33-225bd6fcb9b7%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/1vviNQbdp2U/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAHV4E-c1EcLfpdDRdVnaT0Cyd9_6kF%2BioDr%3Dy_4hKP6HovChBw%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPVExF%2B%2BRnZhe_MyYRUXCKw2Wh_97kwFREVKYN7_sRXNSXDoog%40mail.gmail.com.


Re: Disabling Django Admin, and creating my own three custom admin dashboards

2019-11-10 Thread Motaz Hejaze
I dont know what is your authentication based on , but i faced such a
scenario ..

One of the solutions is to make a middleware that checks the user type with
the url prefix

So usertype1 all related routes will be under /usertype1/

usertype2 all related routes will be under /usertype2/

Middleware will check user_type fron sessions or jwt ( depends on your auth
system ) and compare it with the requested url , if they are identical then
permission guaranteed , else redirect somewhere
On Mon, 11 Nov 2019, 8:14 am Wim Olivier,  wrote:

> Thanks Motaz,
>
> That gives me a little bit of direction.
> I'm thinking now of controlling access to each app's URL's via a single
> piece of middleware (instead of at each View - just have to figure out how
> to do that.
>
> Regards,
> Wim
>
> On Saturday, 9 November 2019 10:44:58 UTC+2, Motaz Hejaze wrote:
>>
>> If you dont want django admin just remove it from installed apps ,
>> middleware and urls..
>>
>> But i dont advice you to do this , you can make you own dashboards and
>> keep django default admin panel ..
>>
>> You need a 3 signup pages and 3 login pages , each signup page will
>> create a different user and each login page will login each user type to
>> his dashboard type ..
>>  I advice you to make a 3 seperate apps to organize the code ..
>>
>> On Sat, 9 Nov 2019, 5:34 am Wim Olivier,  wrote:
>>
>>> Hi everyone,
>>>
>>> I would like to disable the Django Admin, and create my own custom admin
>>> dashboards.
>>> There must be three different types of admin dashboards:
>>> - one for Customers (normal users) where they can do CRUD on their
>>> profile and services (URI: /customer/dashboard)
>>> - one for Partners where they can do CRUD on their users/customers, and
>>> their Customers' profile and services (URI: /partner/dashboard)
>>> - one for Super Users where they can do CRUD on Customers, Partners, and
>>> everything else (URI: /administration)
>>>
>>> I understand very well the ways to extend the User model - that part I'm
>>> OK with.
>>>
>>> Just some practical pointers with a small example, or links to
>>> Django-based repos that implement something like this, please.
>>> I just need some guidance.
>>>
>>> Many thanks!
>>> Wim Olivier
>>> South Africa
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/66befa62-2c5b-4d3d-9653-1c8169ccdcc2%40googlegroups.com
>>> 
>>> .
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/8b2bcb0b-803c-4da2-9d33-225bd6fcb9b7%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHV4E-c1EcLfpdDRdVnaT0Cyd9_6kF%2BioDr%3Dy_4hKP6HovChBw%40mail.gmail.com.


Re: Disabling Django Admin, and creating my own three custom admin dashboards

2019-11-10 Thread Wim Olivier
Thanks Motaz,

That gives me a little bit of direction.
I'm thinking now of controlling access to each app's URL's via a single 
piece of middleware (instead of at each View - just have to figure out how 
to do that.

Regards,
Wim

On Saturday, 9 November 2019 10:44:58 UTC+2, Motaz Hejaze wrote:
>
> If you dont want django admin just remove it from installed apps , 
> middleware and urls..
>
> But i dont advice you to do this , you can make you own dashboards and 
> keep django default admin panel ..
>
> You need a 3 signup pages and 3 login pages , each signup page will create 
> a different user and each login page will login each user type to his 
> dashboard type ..
>  I advice you to make a 3 seperate apps to organize the code ..
>
> On Sat, 9 Nov 2019, 5:34 am Wim Olivier, > 
> wrote:
>
>> Hi everyone,
>>
>> I would like to disable the Django Admin, and create my own custom admin 
>> dashboards.
>> There must be three different types of admin dashboards:
>> - one for Customers (normal users) where they can do CRUD on their 
>> profile and services (URI: /customer/dashboard)
>> - one for Partners where they can do CRUD on their users/customers, and 
>> their Customers' profile and services (URI: /partner/dashboard)
>> - one for Super Users where they can do CRUD on Customers, Partners, and 
>> everything else (URI: /administration)
>>
>> I understand very well the ways to extend the User model - that part I'm 
>> OK with.
>>
>> Just some practical pointers with a small example, or links to 
>> Django-based repos that implement something like this, please.
>> I just need some guidance.
>>
>> Many thanks!
>> Wim Olivier
>> South Africa
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/66befa62-2c5b-4d3d-9653-1c8169ccdcc2%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8b2bcb0b-803c-4da2-9d33-225bd6fcb9b7%40googlegroups.com.


Re: Issue with unique key error on Many to Many field

2019-11-10 Thread Malibu
Hi, thanks for the answer.  Of course, the moment I posted the question I 
figured out what it was.

I ended up checking my primary keys, and found that they didn't have unique 
constraints.  I added them and all was fine.

Must have fallen off during an import.

On Sunday, 10 November 2019 13:55:06 UTC-4, Integr@te System wrote:
>
> Hi Issuer, 
>
> Check your tracker_passenger.
>
> https://docs.djangoproject.com/en/2.2/ref/models/fields/#django.db.models.ManyToManyField
>
>
> On Sun, Nov 10, 2019, 21:40 Malibu > 
> wrote:
>
>> Hi there.  I've been doing Django for awhile but I am stumped on this 
>> one..  I have a many to many relationship with a 'through' definition
>>
>> main.models: 
>>
>> class Client(models.Model):
>> uid = models.CharField(max_length=128, unique=True)
>> key = models.CharField(max_length=128)
>> img = models.TextField()
>> version = models.CharField(max_length=20)
>> lastConnection = models.DateTimeField()
>> role = models.CharField(max_length=128,default="")
>>
>>
>>
>> tracker.models:
>>
>> from main.models import Client
>>
>> class PassengerAccess(models.Model):
>> passenger = models.ForeignKey('Passenger',on_delete=models.CASCADE)
>> client = models.ForeignKey(Client,on_delete=models.CASCADE)
>> created = models.DateTimeField(auto_now_add=True,blank=True)
>> selected = models.BooleanField(default=False)
>>
>> class Passenger(models.Model):
>> first_name = models.CharField(max_length=50)
>> last_name = models.CharField(max_length=50)
>> access_code = models.CharField(max_length=32)
>> school_division = models.ForeignKey(SchoolDivision)
>> open_clients = models.ManyToManyField(Client, through='PassengerAccess')
>>
>>
>> The error I get when I try to migrate is: django.db.utils.ProgrammingError: 
>> there is no unique constraint matching given keys for referenced table 
>> "tracker_passenger"
>>
>> Any solution to this error appears to be related to a foreign key that is 
>> referencing a field that is not unique, but in this case passenger and 
>> client should both be accessing the primary key should they not?  I always 
>> use plain integer primary keys.
>>
>> Any suggestions on how to troubleshoot this would be appreciated.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/db29f623-eecd-4b58-8b70-d2fcd063aaaf%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/76dfb80d-6310-4a4e-a47b-244f00e04ac0%40googlegroups.com.


Re: Django Admin templates not being overwritten by app templates

2019-11-10 Thread Aldian Fazrihady
You need to reorder the app list in INSTALLED_APP setting, so
`django.contrib.admin` is located lower than your app`.

On Mon, Nov 11, 2019 at 3:49 AM Alexander Beach  wrote:

> I am trying to create registration forms using Django's built in auth
> forms.  However, when using the Django admin, the Django admin templates
> are always being used.
>
> My application structure is as follows:
>
> ├── bug
> │   ├── __init__.py
> │   ├── __pycache__
> │   ├── settings.py
> │   ├── urls.py
> │   └── wsgi.py
> ├── db.sqlite3
> ├── manage.py
> └── mysite
> ├── admin.py
> ├── apps.py
> ├── __init__.py
> ├── migrations
> │   └── __init__.py
> ├── models.py
> ├── registration
> ├── templates
> │   └── registration
> │   └── password_reset_form.html
> ├── tests.py
> └── views.py
>
>
>
> My urls.py is the following:
>
>
> from django.contrib import admin
> from django.conf.urls import include, url
> from django.urls import path
>
>
> urlpatterns = [
> path('admin/', admin.site.urls),
> url(r'^accounts/', include('django.contrib.auth.urls'), name="auth"),
> ]
>
>
>
> The mysite/templates/registration/password_reset_form.html is not being
> rendered.  When I navigate to localhost:8000/accounts/password_reset, i can
> see that its using the Django Admin template. See attached screenshot.  I
> am expecting my custom template for the reset form to be rendered.
>
> I am using Django version 2.2.5 and python 3.7.3
>
> Is this a bug or the expected behavior? I don't want to remove the admin
> app.
>
>
>
>
> --
> 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/c718299d-53f6-4e56-8976-a2040f3449ac%40googlegroups.com
> 
> .
>


-- 
Regards,

Aldian Fazrihady
http://aldianfazrihady.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAN7EoAabPjVcLDgou_Ee_aK899E3KiVvxSGSkqA0hqXhDiU1BQ%40mail.gmail.com.


Re: Sending mail

2019-11-10 Thread franz ulenaers

I am missing here the file  = views.py
Also the " from apps.validators import validaRut " gives problems 
because i am missing also the validators.py file


Op 10/11/2019 om 12:54 schreef Franz Ulenaers:

- how to implement these files into my project ?
- have i to startapp “register” into my project ?
- i believe models.py , urls.py , forms.py and Admin.py should be put 
into the register folder 

- login.html in the folder templates/
Thanks
Franz

Verstuurd vanaf mijn iPhone

Op 8 nov. 2019 om 22:04 heeft DANIEL URBANO DE LA RUA 
mailto:dannybombas...@gmail.com>> het 
volgende geschreven:



Hablas español?

On Fri, 8 Nov 2019, 17:59 Daniel Angel, > wrote:


LOGIN.HTML

{% extends "register/base.html" %}
{% block content %}






{{ form.non_field_errors }}
{% for field in form %}
{{ field }}
{{ field.errors }}

{% endfor %}
Iniciar sesión

{% csrf_token %}






Registro de Cliente 
Olvidé mi contraseña



{% endblock %}
MODELO.PY
from django.db import models
from django.core.mail import send_mail
from django.contrib.auth.models import PermissionsMixin
from django.contrib.auth.base_user import AbstractBaseUser
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
from django.contrib.auth.base_user import BaseUserManager
from apps.validators import validaRut
class UserManager(BaseUserManager):
"""Administrador de usuariosー"""
use_in_migrations = True
def _create_user(self, email, password, **extra_fields):
"""Create and save a user with the given username, email, and
password."""
if not email:
raise ValueError('The given email must be set')
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
def create_user(self, email, password=None, **extra_fields):
extra_fields.setdefault('is_staff', False)
extra_fields.setdefault('is_superuser', False)
return self._create_user(email, password, **extra_fields)
def create_superuser(self, email, password, **extra_fields):
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
if extra_fields.get('is_staff') is not True:
raise ValueError('Superuser must have is_staff=True.')
if extra_fields.get('is_superuser') is not True:
raise ValueError('Superuser must have is_superuser=True.')
return self._create_user(email, password, **extra_fields)
class User(AbstractBaseUser, PermissionsMixin):
"""Modelo de usuario personalizado
username Sin usar、email La dirección se usa como nombre de usuario.
"""
email
= models.EmailField(_('dirección de correo electrónico'),
unique=True)
first_name = models.CharField(_('Nombre'), max_length=30,
blank=True)
last_name = models.CharField(_('Apellido'), max_length=150,
blank=True)
rut = models.CharField(_('Rut'), validators= [validaRut],
max_length=10,blank=True, help_text="Ejemplo: 111-1")
is_staff = models.BooleanField(
_('staff status'),
default=False,
help_text=_(
'Designa si el usuario puede iniciar sesión en este sitio de 
administración.'),
)
is_active = models.BooleanField(
_('active'),
default=True,
help_text=_(
'Designa si este usuario debe ser tratado como activo. '
'Anule la selección de esto en lugar de eliminar cuentas.'
),
)
date_joined = models.DateTimeField(_('date joined'),
default=timezone.now)
objects = UserManager()
EMAIL_FIELD = 'email'
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
class Meta:
verbose_name = _('user')
verbose_name_plural = _('users')
def get_full_name(self):
"""Devuelve el primer nombre más el último nombre, con un espacio"""
full_name = '%s%s' % (self.first_name, self.last_name,
self.rut)
return full_name.strip()
def get_short_name(self):
"""Devuelve el nombre corto para el usuario."""
return self.first_name
def get_rut_name(self):
"""Devuelve el rut."""
return self.rut
def email_user(self, subject, message, from_email=None, **kwargs):
"""Enviar un correo electrónico a este usuario."""
send_mail(subject, message, from_email, [self.email], **kwargs)
@property
def username(self):
return self.email
URLS.PY
from django.urls import path
from . import views
app_name = 'register'
urlpatterns = [
path('', views.Top.as_view(), name='top'),
path('login/', views.Login.as_

Re: Django Admin templates not being overwritten by app templates

2019-11-10 Thread Alexander Beach
This behavior seems counter intuitive, and contrary to what the 
documentation says

For example: my settings.py file is as follows:

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]


According to this documentation, APP_DIR should behave as follows:

https://docs.djangoproject.com/en/2.2/howto/overriding-templates/#overriding-from-an-app-s-template-directory

> With APP_DIRS 

 set 
to True, the template loader will look in the app’s templates directory and 
find the templates.

This isn't the behavior that is happening. djang_admin and mysite are 
technically separate apps, and have seperate template directories. 

On Sunday, November 10, 2019 at 3:49:32 PM UTC-5, Alexander Beach wrote:
>
> I am trying to create registration forms using Django's built in auth 
> forms.  However, when using the Django admin, the Django admin templates 
> are always being used.
>
> My application structure is as follows:
>
> ├── bug
> │   ├── __init__.py
> │   ├── __pycache__
> │   ├── settings.py
> │   ├── urls.py
> │   └── wsgi.py
> ├── db.sqlite3
> ├── manage.py
> └── mysite
> ├── admin.py
> ├── apps.py
> ├── __init__.py
> ├── migrations
> │   └── __init__.py
> ├── models.py
> ├── registration
> ├── templates
> │   └── registration
> │   └── password_reset_form.html
> ├── tests.py
> └── views.py
>
>
>
> My urls.py is the following:
>
>
> from django.contrib import admin
> from django.conf.urls import include, url
> from django.urls import path
>
>
> urlpatterns = [
> path('admin/', admin.site.urls),
> url(r'^accounts/', include('django.contrib.auth.urls'), name="auth"),
> ]
>
>
>
> The mysite/templates/registration/password_reset_form.html is not being 
> rendered.  When I navigate to localhost:8000/accounts/password_reset, i can 
> see that its using the Django Admin template. See attached screenshot.  I 
> am expecting my custom template for the reset form to be rendered.
>
> I am using Django version 2.2.5 and python 3.7.3
>
> Is this a bug or the expected behavior? I don't want to remove the admin 
> app. 
>
>
>
>
>

-- 
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/0520c4c2-abbb-441c-bd81-1aeeb8c355b8%40googlegroups.com.


Re: Django Admin templates not being overwritten by app templates

2019-11-10 Thread Mike Dewhirst

On 11/11/2019 7:02 am, Alexander Beach wrote:
I am trying to create registration forms using Django's built in auth 
forms.  However, when using the Django admin, the Django admin 
templates are always being used.


My application structure is as follows:

|
├──bug
│├──__init__.py
│├──__pycache__
│├──settings.py
│├──urls.py
│└──wsgi.py
├──db.sqlite3
├──manage.py
└──mysite
├──admin.py
├──apps.py
├──__init__.py
├──migrations
│└──__init__.py
├──models.py
├──registration
├──templates
|

| mysite/templates/admin/password_reset_form.html

Not tested but that's the principle. Django will default to using the 
template from your site rather than its own. The admin is one of your 
apps so it will use any templates it finds (that urls.conf knows about) 
in your main templates directory.


Cheers

Mike

|

|
│└──registration
│└──password_reset_form.html
├──tests.py
└──views.py

|


My urls.py is the following:


|
fromdjango.contrib importadmin
fromdjango.conf.urls importinclude,url
fromdjango.urls importpath


urlpatterns =[
    path('admin/',admin.site.urls),
    url(r'^accounts/',include('django.contrib.auth.urls'),name="auth"),
]

|


The mysite/templates/registration/password_reset_form.html is not 
being rendered.  When I navigate to 
localhost:8000/accounts/password_reset, i can see that its using the 
Django Admin template. See attached screenshot.  I am expecting my 
custom template for the reset form to be rendered.


I am using Django version 2.2.5 and python 3.7.3

Is this a bug or the expected behavior? I don't want to remove the 
admin app.





--
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/c718299d-53f6-4e56-8976-a2040f3449ac%40googlegroups.com 
.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2e77a76e-e6a5-392c-acd9-4694e260a42e%40dewhirst.com.au.


Django Admin templates not being overwritten by app templates

2019-11-10 Thread Alexander Beach
I am trying to create registration forms using Django's built in auth 
forms.  However, when using the Django admin, the Django admin templates 
are always being used.

My application structure is as follows:

├── bug
│   ├── __init__.py
│   ├── __pycache__
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
├── db.sqlite3
├── manage.py
└── mysite
├── admin.py
├── apps.py
├── __init__.py
├── migrations
│   └── __init__.py
├── models.py
├── registration
├── templates
│   └── registration
│   └── password_reset_form.html
├── tests.py
└── views.py



My urls.py is the following:


from django.contrib import admin
from django.conf.urls import include, url
from django.urls import path


urlpatterns = [
path('admin/', admin.site.urls),
url(r'^accounts/', include('django.contrib.auth.urls'), name="auth"),
]



The mysite/templates/registration/password_reset_form.html is not being 
rendered.  When I navigate to localhost:8000/accounts/password_reset, i can 
see that its using the Django Admin template. See attached screenshot.  I 
am expecting my custom template for the reset form to be rendered.

I am using Django version 2.2.5 and python 3.7.3

Is this a bug or the expected behavior? I don't want to remove the admin 
app. 




-- 
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/c718299d-53f6-4e56-8976-a2040f3449ac%40googlegroups.com.


Re: Issue with unique key error on Many to Many field

2019-11-10 Thread Integr@te System
Hi Issuer,

Check your tracker_passenger.
https://docs.djangoproject.com/en/2.2/ref/models/fields/#django.db.models.ManyToManyField


On Sun, Nov 10, 2019, 21:40 Malibu  wrote:

> Hi there.  I've been doing Django for awhile but I am stumped on this
> one..  I have a many to many relationship with a 'through' definition
>
> main.models:
>
> class Client(models.Model):
> uid = models.CharField(max_length=128, unique=True)
> key = models.CharField(max_length=128)
> img = models.TextField()
> version = models.CharField(max_length=20)
> lastConnection = models.DateTimeField()
> role = models.CharField(max_length=128,default="")
>
>
>
> tracker.models:
>
> from main.models import Client
>
> class PassengerAccess(models.Model):
> passenger = models.ForeignKey('Passenger',on_delete=models.CASCADE)
> client = models.ForeignKey(Client,on_delete=models.CASCADE)
> created = models.DateTimeField(auto_now_add=True,blank=True)
> selected = models.BooleanField(default=False)
>
> class Passenger(models.Model):
> first_name = models.CharField(max_length=50)
> last_name = models.CharField(max_length=50)
> access_code = models.CharField(max_length=32)
> school_division = models.ForeignKey(SchoolDivision)
> open_clients = models.ManyToManyField(Client, through='PassengerAccess')
>
>
> The error I get when I try to migrate is: django.db.utils.ProgrammingError: 
> there is no unique constraint matching given keys for referenced table 
> "tracker_passenger"
>
> Any solution to this error appears to be related to a foreign key that is 
> referencing a field that is not unique, but in this case passenger and client 
> should both be accessing the primary key should they not?  I always use plain 
> integer primary keys.
>
> Any suggestions on how to troubleshoot this would be appreciated.
>
> --
> 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/db29f623-eecd-4b58-8b70-d2fcd063aaaf%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAP5HUWr3kVimTG1NE80iBFr4kNPyhEyfcTN39fGo%2BAAmv7O%3DnQ%40mail.gmail.com.


Issue with unique key error on Many to Many field

2019-11-10 Thread Malibu
Hi there.  I've been doing Django for awhile but I am stumped on this 
one..  I have a many to many relationship with a 'through' definition

main.models: 

class Client(models.Model):
uid = models.CharField(max_length=128, unique=True)
key = models.CharField(max_length=128)
img = models.TextField()
version = models.CharField(max_length=20)
lastConnection = models.DateTimeField()
role = models.CharField(max_length=128,default="")



tracker.models:

from main.models import Client

class PassengerAccess(models.Model):
passenger = models.ForeignKey('Passenger',on_delete=models.CASCADE)
client = models.ForeignKey(Client,on_delete=models.CASCADE)
created = models.DateTimeField(auto_now_add=True,blank=True)
selected = models.BooleanField(default=False)

class Passenger(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
access_code = models.CharField(max_length=32)
school_division = models.ForeignKey(SchoolDivision)
open_clients = models.ManyToManyField(Client, through='PassengerAccess')


The error I get when I try to migrate is: django.db.utils.ProgrammingError: 
there is no unique constraint matching given keys for referenced table 
"tracker_passenger"

Any solution to this error appears to be related to a foreign key that is 
referencing a field that is not unique, but in this case passenger and client 
should both be accessing the primary key should they not?  I always use plain 
integer primary keys.

Any suggestions on how to troubleshoot this would be appreciated.

-- 
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/db29f623-eecd-4b58-8b70-d2fcd063aaaf%40googlegroups.com.


Re: Sending mail

2019-11-10 Thread Franz Ulenaers
- how to implement these files into my project ?
- have i to startapp “register” into my project ?
- i believe models.py , urls.py , forms.py and Admin.py should be put into the 
register folder 
- login.html in the folder templates/
Thanks
Franz

Verstuurd vanaf mijn iPhone

> Op 8 nov. 2019 om 22:04 heeft DANIEL URBANO DE LA RUA 
>  het volgende geschreven:
> 
> Hablas español?
> 
>> On Fri, 8 Nov 2019, 17:59 Daniel Angel,  wrote:
>> LOGIN.HTML
>> 
>> {% extends "register/base.html" %}
>> {% block content %}
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> {{ form.non_field_errors }}
>> {% for field in form %}
>> {{ field }}
>> {{ field.errors }}
>> 
>> {% endfor %}
>> Iniciar 
>> sesión
>> 
>> {% csrf_token %}
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> Registro de Cliente 
>> Olvidé mi contraseña
>> 
>> 
>> 
>> 
>> {% endblock %}
>> 
>> 
>> MODELO.PY
>> 
>> 
>> 
>> from django.db import models
>> from django.core.mail import send_mail
>> from django.contrib.auth.models import PermissionsMixin
>> from django.contrib.auth.base_user import AbstractBaseUser
>> from django.utils.translation import ugettext_lazy as _
>> from django.utils import timezone
>> from django.contrib.auth.base_user import BaseUserManager
>> from apps.validators import validaRut
>> 
>> class UserManager(BaseUserManager):
>> """Administrador de usuariosー"""
>> use_in_migrations = True
>> 
>> def _create_user(self, email, password, **extra_fields):
>> """Create and save a user with the given username, email, and
>> password."""
>> if not email:
>> raise ValueError('The given email must be set')
>> email = self.normalize_email(email)
>> 
>> user = self.model(email=email, **extra_fields)
>> user.set_password(password)
>> user.save(using=self._db)
>> return user
>> 
>> def create_user(self, email, password=None, **extra_fields):
>> extra_fields.setdefault('is_staff', False)
>> extra_fields.setdefault('is_superuser', False)
>> return self._create_user(email, password, **extra_fields)
>> 
>> def create_superuser(self, email, password, **extra_fields):
>> extra_fields.setdefault('is_staff', True)
>> extra_fields.setdefault('is_superuser', True)
>> 
>> if extra_fields.get('is_staff') is not True:
>> raise ValueError('Superuser must have is_staff=True.')
>> if extra_fields.get('is_superuser') is not True:
>> raise ValueError('Superuser must have is_superuser=True.')
>> 
>> return self._create_user(email, password, **extra_fields)
>> 
>> 
>> class User(AbstractBaseUser, PermissionsMixin):
>> """Modelo de usuario personalizado
>> 
>> username Sin usar、email La dirección se usa como nombre de usuario.
>> 
>> """
>> email = models.EmailField(_('dirección de correo electrónico'), 
>> unique=True)
>> first_name = models.CharField(_('Nombre'), max_length=30, blank=True)
>> last_name = models.CharField(_('Apellido'), max_length=150, blank=True)
>> rut = models.CharField(_('Rut'), validators= [validaRut], 
>> max_length=10,blank=True, help_text="Ejemplo: 111-1")
>> 
>> is_staff = models.BooleanField(
>> _('staff status'),
>> default=False,
>> help_text=_(
>> 'Designa si el usuario puede iniciar sesión en este sitio de 
>> administración.'),
>> )
>> is_active = models.BooleanField(
>> _('active'),
>> default=True,
>> help_text=_(
>> 'Designa si este usuario debe ser tratado como activo. '
>> 'Anule la selección de esto en lugar de eliminar cuentas.'
>> ),
>> )
>> date_joined = models.DateTimeField(_('date joined'), 
>> default=timezone.now)
>> 
>> objects = UserManager()
>> 
>> EMAIL_FIELD = 'email'
>> USERNAME_FIELD = 'email'
>> REQUIRED_FIELDS = []
>> 
>> class Meta:
>> verbose_name = _('user')
>> verbose_name_plural = _('users')
>> 
>> def get_full_name(self):
>> """Devuelve el primer nombre más el último nombre, con un espacio"""
>> full_name = '%s %s' % (self.first_name, self.last_name, self.rut)
>> return full_name.strip()
>> 
>> def get_short_name(self):
>> """Devuelve el nombre corto para el usuario."""
>> return self.first_name
>> 
>> def get_rut_name(self):
>> """Devuelve el rut."""
>> return self.rut
>> 
>> def email_user(self, subject, message, from_email=None, **kwargs):
>> """Enviar un correo electrónico a este usuario."""
>> send_mail(subject, message, from_email, [self.email], **kwargs)
>> 
>> @property
>> def username