Re: Issues with creating an app

2020-04-17 Thread Motaz Hejaze
Please try to follow the official tutorial of django ...

'Images.views.home' is not a string ..

Try yo put without ' '


On Sat, 18 Apr 2020, 1:44 am Leonardo Salvador Diego Solis, <
leonardo.diego110...@gmail.com> wrote:

> Hello, this is the first time I use Django (I'm learning with free courses
> on internet) and I'm trying to make an app to print something. I don't know
> what I have to do, I don't understand at all the problem. Please, I would
> appreciate so much your help
>
> PD: I'm not a native english speaker, I speak Spanish, so I'm sorry if  I
> wrote bad. Also I put pics about what I get :(
>
>
> --
> 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/b1a666b1-5a2d-4e6d-b214-06fcce1abda2%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-cNjSFtxCFNXisA2SkHcceUQpDFjKLw8OktGb%3Dq_u2Pdw%40mail.gmail.com.


Re: [PROBLEM] Creacion de primera apps de djangogirls, error en models.py

2020-04-17 Thread Juan Pablo Romero Bernal
Saludos Lucas,

Sería de mucha utilidad que nos mostraras los mensajes de error que
obtienes para
poder ayudarte.

Saludos,

On Fri, Apr 17, 2020 at 4:34 PM lucas bonet  wrote:

> Hola, estoy creando la primera aplicacion de django con pyton y cuando
> llega el momento de configurar en el directorio de blog--> model.py copio
> las lineas de comando del tutrorial y me reporta errores. los erorres me
> los marca en From, como que no tiene una carpeta otra de acceso llamada
> django.conf y asi con los otros dos archivos. A donde tendria que cambiar
> esa configuracion para poder continuar?
>  Muchas gracias y espero poder sumarme a la comunidad para ir creciendo.
> Saludos!
> from django.conf import settings
> from django.db import models
> from django.utils import timezone
>
>
> --
> 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/24d95b2d-d336-440c-b816-57820afa57f0%40googlegroups.com
> 
> .
>


-- 
Juan

-- 
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/CAJK1Jg1OtZ-AO-SwxL-hLn1pd9V%3D3VqqPp2WPUyLEkso%2BXTn-g%40mail.gmail.com.


Re: Capture URL values in a CBV

2020-04-17 Thread Tim Johnson

Wham! That is what I was looking for.

From a class-based-view virgin to a wise head:

**you have been so helpful**

thank you

On 4/17/20 1:08 PM, Dylan Reinhold wrote:

def get_context_data(self, **kwargs):
        # Call the base implementation first to get a context
        context = super().get_context_data(**kwargs)
        # You your stuff
        context['my_pk'] = self.kwargs['pk']
        return context


--
Tim
tj49.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/106db642-7f41-1cd5-b20b-a0db77f2c854%40akwebsoft.com.


[PROBLEM] Creacion de primera apps de djangogirls, error en models.py

2020-04-17 Thread lucas bonet
Hola, estoy creando la primera aplicacion de django con pyton y cuando 
llega el momento de configurar en el directorio de blog--> model.py copio 
las lineas de comando del tutrorial y me reporta errores. los erorres me 
los marca en From, como que no tiene una carpeta otra de acceso llamada 
django.conf y asi con los otros dos archivos. A donde tendria que cambiar 
esa configuracion para poder continuar?
 Muchas gracias y espero poder sumarme a la comunidad para ir creciendo. 
Saludos!
from django.conf import settings
from django.db import models
from django.utils import timezone


-- 
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/24d95b2d-d336-440c-b816-57820afa57f0%40googlegroups.com.


Re: Interfaz Gráfica (Frontend)

2020-04-17 Thread Gustavo Andres Angulo
Hola, puedes seguir el tutorial usando en el Proyecto de Django Girls,
https://tutorial.djangogirls.org/es/

Allí puedes apoyarte con la documentación de Django.

On Fri, Apr 17, 2020 at 7:56 AM Denilson Antonio Avellan <
denilson.d...@gmail.com> wrote:

> Hola comunidad estoy empezando con Django me parece super genial pero
> quiero empezar con las interfaces gráficas por ejemplo necesito ejemplos o
> plantillas de login. menus. vistas etc. y queria saber en que me pueden
> ayudar mandandome links donde me pueda guiar!
>
> Muchas Gracias..!!
>
> --
> 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/df15c69c-d84f-45b9-9663-37d6b4b9ae69%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/CAJovUb%3D1Gx30U3KN6OrVvsF%3DYNHJH6jqsHQGOsRKyqEOZnLdvA%40mail.gmail.com.


Re: Capture URL values in a CBV

2020-04-17 Thread Dylan Reinhold
Tim you want to use get_context_data to add more data into your context for
the template

def get_context_data(self, **kwargs):
# Call the base implementation first to get a context
context = super().get_context_data(**kwargs)
# You your stuff
context['my_pk'] = self.kwargs['pk']
return context


Then in your template you get get it as {{ my_pk }}
See
https://docs.djangoproject.com/en/3.0/topics/class-based-views/generic-display/#adding-extra-context

Dylan

On Fri, Apr 17, 2020 at 1:49 PM Tim Johnson  wrote:

> OK. I am abandoning all pretext at self-sufficiency here. I have
> researched this for days, reviewed the links below and I still cannot
> resolve this issue.
>
> Maybe someone besides Gavin has an idea of how to capture the pattern
> between angle brackets in a url conf into a class-based view.
>
> I am sure the solution is very easy, but I obviously am missing something.
>
> thanks
> On 4/16/20 7:26 AM, Tim Johnson wrote:
>
>
> On 4/15/20 7:24 PM, Gavin Wiener wrote:
>
> Hey Tim
>
> Hello Gavin: Thank you for your prompt reply.
>
>
> The bigger question is, what are you trying to achieve?
>
> I gotta know. I'm a retired programmer with 19 years doing CGI. Wrote and
> implemented my own framework. First in C, than C++ then rebol, then python.
>
> I really want to know what is going on "under the hood" but I also wish to
> know why those examples, taken from documentation do not work.
>
> I'm building a website with django as an alternative to the original in
> Drupal because I want fine-grained control.
>
> I hope that answers your question.
>
>
> With the DetailView, fetching the object with the primary key is already
> handled for you, as you've seen the object will already be available in the
> template.
>
> This website is very useful to know which functions are implemented in a
> class-based view, and which variables are available.
>
> http://ccbv.co.uk/
>
> Thanks for the link. Will study it after finishing my coffee.
>
>
> On Thursday, April 16, 2020 at 8:26:00 AM UTC+8, tim042849 wrote:
>>
>> using django.VERSION (2, 1, 5, 'final', 0) with
>>
>> python 3.7.2 on ubuntu 16.04
>>
>> Given the URL pattern below:
>>
>> path('', ArticleDetailView.as_view(), name='article_detail'),
>>
>> And the view as below:
>>
>> class ArticleDetailView(DetailView):
>> model = Article
>> template_name = 'article_detail.html'
>> login_url = 'login'
>>
>> I can access the variable pk from a template as
>>
>> article.pk
>>
>> But I don't know how to access the pk variable from the view itself.
>>
>> Adding the get_queryset method to the view doesn't work
>>
>> example
>>
>> def get_queryset(self):
>> print(self.kwargs["pk"])
>>
>> results in
>>
>> 'NoneType' object has no attribute 'filter'
>>
>> Trying
>> def get_object(self):
>> queryset = self.filter_queryset(self.get_queryset())
>> obj = queryset.get(pk=self.kwargs['pk'])
>> return obj
>> results in
>>   'ArticleDetailView' object has no attribute 'filter_queryset'
>>
>> Please advise - pretty basic for django, new to me :)
>> thanks
>>
>> --
>> Timtj49.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/39595843-0a01-4ffb-95b9-46d2d3c442e3%40googlegroups.com
> 
> .
>
> --
> Timtj49.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/52390ecd-3748-6c96-3a1b-a2d671322336%40akwebsoft.com
> 
> .
>
> --
> Timtj49.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/a365875b-a4a1-2214-8616-c2b749f2ef52%40akwebsoft.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 

Re: Capture URL values in a CBV

2020-04-17 Thread Tim Johnson
OK. I am abandoning all pretext at self-sufficiency here. I have 
researched this for days, reviewed the links below and I still cannot 
resolve this issue.


Maybe someone besides Gavin has an idea of how to capture the pattern 
between angle brackets in a url conf into a class-based view.


I am sure the solution is very easy, but I obviously am missing something.

thanks

On 4/16/20 7:26 AM, Tim Johnson wrote:



On 4/15/20 7:24 PM, Gavin Wiener wrote:

Hey Tim

Hello Gavin: Thank you for your prompt reply.


The bigger question is, what are you trying to achieve?


I gotta know. I'm a retired programmer with 19 years doing CGI. Wrote 
and implemented my own framework. First in C, than C++ then rebol, 
then python.


I really want to know what is going on "under the hood" but I also 
wish to know why those examples, taken from documentation do not work.


I'm building a website with django as an alternative to the original 
in Drupal because I want fine-grained control.


I hope that answers your question.



With the DetailView, fetching the object with the primary key is 
already handled for you, as you've seen the object will already be 
available in the template.


This website is very useful to know which functions are implemented 
in a class-based view, and which variables are available.


http://ccbv.co.uk/


Thanks for the link. Will study it after finishing my coffee.


On Thursday, April 16, 2020 at 8:26:00 AM UTC+8, tim042849 wrote:

using django.VERSION (2, 1, 5, 'final', 0) with

python 3.7.2 on ubuntu 16.04

Given the URL pattern below:

path('', ArticleDetailView.as_view(), name='article_detail'),

And the view as below:

class ArticleDetailView(DetailView):
    model = Article
    template_name = 'article_detail.html'
    login_url = 'login'

I can access the variable pk from a template as

article.pk 

But I don't know how to access the pk variable from the view itself.

Adding the get_queryset method to the view doesn't work

example

def get_queryset(self):
    print(self.kwargs["pk"])

results in

'NoneType' object has no attribute 'filter' Trying def
get_object(self): queryset =
self.filter_queryset(self.get_queryset()) obj =
queryset.get(pk=self.kwargs['pk']) return obj results in
'ArticleDetailView' object has no attribute 'filter_queryset'
Please advise - pretty basic for django, new to me :) thanks

-- 
Tim

tj49.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/39595843-0a01-4ffb-95b9-46d2d3c442e3%40googlegroups.com 
.

--
Tim
tj49.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/52390ecd-3748-6c96-3a1b-a2d671322336%40akwebsoft.com 
.


--
Tim
tj49.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/a365875b-a4a1-2214-8616-c2b749f2ef52%40akwebsoft.com.


Re: Callable field in fieldset's field

2020-04-17 Thread Gagan Deep
Thanks Federico, it did solved the problem.



On Fri, Apr 17, 2020 at 6:28 AM 'Federico Capoano' via Django users <
django-users@googlegroups.com> wrote:

> Is this the kind of thing you're looking for?
>
> https://github.com/openwisp/openwisp-firmware-upgrader/tree/1e9fa26d75a48ae9274c2708ea9a10134a2bb9d0/openwisp_firmware_upgrader/base/admin.py#L150-L186
>
> Fed
>
>
> On Wednesday, April 15, 2020 at 4:15:48 PM UTC-5, Gagan Deep wrote:
>>
>> Greetings of the day,
>>
>> I have defined a model admin inheriting from admin.ModelAdmin class.
>> There is one of the fields which I want to show on the admin dashboard
>> which is a function. I read in Django docs that for a callable function to
>> be a field, it should be added in readonly_fields. So far, it was working
>> great. The problem arose when I mentioned that callable field in the
>> fieldset.
>>
>> This worked fine:
>> class Myadmin(admin.ModelAdmin):
>> readonly_fields = ('my_callable_field', )
>> fields = ('my_callable_field' )
>>
>>
>> But, doing this popped Unknown field(s) (my_callable_field) specified for
>>  . Check fields/fieldsets/exclude attributes of class Myadmin
>> class Myadmin(admin.ModelAdmin):
>> readonly_fields = ('my_callable_field', )
>> fieldsets = (
>> (None, {'fields': ('my_callable_field',)}),
>> )
>>
>> I don't understand why this is happening.
>>
> --
> 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/dd24c6eb-fcaa-41dc-ac78-6f2ba700c5e9%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/CAOX69xp0%3DyjN0HdFyGqT5qb5fdoPM8g%2BSvQxEmfgJxtM1Ly5qw%40mail.gmail.com.


How to modify messages displayed in Admin change page?

2020-04-17 Thread Mark Phillips
I have a model Document, and the admin can upload an image to a FileField.
When a document/image is successfully uploaded, I also save a sha256
"fingerprint" of the image to test if an admin tries to upload a duplicate
image. If a duplicate image is detected, I don't save the duplicate image
and display an error message to the admin through the messages framework.
However, I also get the message that the document was successfully
uploaded. How can I prevent this from happening?

My code in an abbreviated form:
class Document(Model):
document_id = models.AutoField(primary_key=True)
computed_sha256 = models.CharField(editable=False, max_length=64,
default="foobar")
storage_file_name = models.FileField('File name',
upload_to=settings.DOCUMENT_FOLDER_ORIGINALS,
default=settings.DEFAULT_IMAGE_XXXLARGE_PATH,)

class DocumentAdmin(admin.ModelAdmin):

def save_model(self, request, obj, form, change):
if form.is_valid():
if not change:
# Uploading one or more images
files = request.FILES.getlist('storage_file_name')
if files:
for f in files:
# Check if this file has been uploaded before by
checking the fingerprint
_file = form.cleaned_data["storage_file_name"]
sha256 =
image_processing_utils.compute_sha256(_file)
duplicate_files =
Document.objects.filter(computed_sha256 = sha256)
if len(duplicate_files) > 0:
messages.add_message(request, messages.WARNING,
'Uploading a duplicate of "%s" and it will not be saved' % f.name)
break;
# more image processing stuff
else:
# some more image processing stuff
obj.metadata = form.cleaned_data['metadata']
super().save_model(request, obj, form, change)

The attached image shows the problem.

Where can I find the message that the document was saved properly and
remove it from the messages list?

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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEqej2MeVGfXhen2FE542Yhcin2os5fpGrSkQsj%3DZ%2BiYVFKHLQ%40mail.gmail.com.


Reg: Django signal not working

2020-04-17 Thread 'Amitesh Sahay' via Django users
Hi,
I am creating a Django signup form through "User" model and "UserCreationForm" 
and customized the User model to accommodate single user defined field 
"contact".

However, the signal that I have written seems not to be working.
Whenever, I am filling the form, I am getting below error:
AttributeError at /auth/register/'User' object has no attribute 'profile'
Full traceback log as below:
Installed Applications:['django.contrib.admin', 'django.contrib.auth', 
'django.contrib.contenttypes', 'django.contrib.sessions', 
'django.contrib.messages', 'django.contrib.staticfiles', 'phone_field', 
'AUTHENTICATION']Installed 
Middleware:['django.middleware.security.SecurityMiddleware', 
'django.contrib.sessions.middleware.SessionMiddleware', 
'django.middleware.common.CommonMiddleware', 
'django.middleware.csrf.CsrfViewMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware', 
'django.contrib.messages.middleware.MessageMiddleware', 
'django.middleware.clickjacking.XFrameOptionsMiddleware']


Traceback (most recent call last):  File 
"C:\Python38\lib\site-packages\django\core\handlers\exception.py", line 34, in 
inner    response = get_response(request)  File 
"C:\Python38\lib\site-packages\django\core\handlers\base.py", line 115, in 
_get_response    response = self.process_exception_by_middleware(e, request)  
File "C:\Python38\lib\site-packages\django\core\handlers\base.py", line 113, in 
_get_response    response = wrapped_callback(request, *callback_args, 
**callback_kwargs)  File 
"C:\Users\anshu\djago-project\SkoolSkill\AUTHENTICATION\views.py", line 50, in 
register_user    save1 = form.save()  File 
"C:\Python38\lib\site-packages\django\contrib\auth\forms.py", line 137, in save 
   user.save()  File 
"C:\Python38\lib\site-packages\django\contrib\auth\base_user.py", line 66, in 
save    super().save(*args, **kwargs)  File 
"C:\Python38\lib\site-packages\django\db\models\base.py", line 745, in save    
self.save_base(using=using, force_insert=force_insert,  File 
"C:\Python38\lib\site-packages\django\db\models\base.py", line 793, in 
save_base    post_save.send(  File 
"C:\Python38\lib\site-packages\django\dispatch\dispatcher.py", line 173, in 
send    return [  File 
"C:\Python38\lib\site-packages\django\dispatch\dispatcher.py", line 174, in 
    (receiver, receiver(signal=self, sender=sender, **named))  File 
"C:\Users\anshu\djago-project\SkoolSkill\AUTHENTICATION\models.py", line 17, in 
save_user_profile    instance.profile.save()
Exception Type: AttributeError at /auth/register/Exception Value: 'User' object 
has no attribute 'profile'
I have uploaded the project in google drive with below location link, just in 
case if somebody wishes to test it.
https://drive.google.com/file/d/1COB3BBoRb95a85cLi9k1PdIYD3bmlnc0/view?usp=sharing
My environment:
Django==3.0.5 python 3.8.2
Not sure what is the mistake. Please help.
models.py
from django.db import modelsfrom django.contrib.auth.models import Userfrom 
django.db.models.signals import post_savefrom django.dispatch import receiver
class SignUp(models.Model):    user = models.OneToOneField(User, 
on_delete=models.CASCADE)    Contact = models.TextField(max_length=500, 
blank=True)
@receiver(post_save, sender=User)def create_user_profile(sender, instance, 
created, **kwargs):    if created:        SignUp.objects.create(user=instance)
@receiver(post_save, sender=User)def save_user_profile(sender, instance, 
**kwargs):    instance.profile.save()
forms.py
from django.contrib.auth.forms import UserCreationFormfrom 
django.contrib.auth.models import Userfrom django import formsfrom  .models 
import SignUp
class SignUpForm(UserCreationForm):    email = forms.EmailField()    first_name 
= forms.CharField(max_length=100)    last_name = 
forms.CharField(max_length=100)#    phone = format()
    class Meta:        model = User        fields = ('username', 'first_name', 
'last_name', 'email', 'password1', 'password2')

class CustomSignUpPage(forms.ModelForm):    Contact = 
forms.CharField(max_length=10)    class Meta:        model = SignUp        
fields = ('Contact', )
views.py
from django.shortcuts import render, redirectfrom django.contrib.auth import 
authenticate, login, logoutfrom django.contrib import messages#from 
django.contrib.auth.forms import UserCreationFormfrom .forms import SignUpForm, 
CustomSignUpPage
def home(request):   return render(request, 'authenticate\home.html', {})
def login_user(request):   if request.method == 'POST':      username = 
request.POST['username']      password = request.POST['password']      user = 
authenticate(request, username=username, password=password)      if user is not 
None:         login(request, user)         messages.success(request, ('login 
success'))         return redirect('home')      else:         
messages.success(request, ('error while login, please try again'))         
return redirect('login')   else:      return render(request, 
'authenticate\login.html', {})
def logout_user(request):   

Re: problem with admin panel

2020-04-17 Thread Cristhian Heredia Claure
thanks for yor reply, and yes y Did that, my static files created 
correctly, but the admin page still without Stlye, I really don't 
understand, because in my Raspberry Pi I didn't do any other configuration 
and the admin page is perfect.

El viernes, 17 de abril de 2020, 7:32:56 (UTC-4), Andréas Kühne escribió:
>
> This sounds like you are having problems with the static files - check so 
> that you have run "manage.py collectstatic" correctly and that the command 
> works.
>
> Regards,
>
> Andréas
>
>
> Den fre 17 apr. 2020 kl 03:57 skrev Cristhian Heredia Claure <
> cris...@gmail.com >:
>
>>
>> Hello everyone Sorry if it's not correct to post here this issue that I 
>> have... In a LINUX environment, after all configuration for my project, 
>> when I try to log in the admin site, the style of the page of the admin 
>> panel is well stylized, as it should be.
>> But in the test that I did in a Windows environment (the same 
>> configuration), everything is correct, but the page of the administration 
>> panel does not have any style, why is this? I search in many forums but I 
>> could not find a solution. Thanks in advance.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/c26e722d-69fd-4dd2-9e32-94f451cf8e0f%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/6ffb5e9d-9cc6-4900-9ecd-14d3beed32c2%40googlegroups.com.


Re: Models as choices

2020-04-17 Thread Esther Camilo
This guy has plenty of tutorials building complete applications. As
front-end you can use Bootstrap in your templates
https://simpleisbetterthancomplex.com/



On Fri, Apr 17, 2020 at 9:57 AM Denilson Antonio Avellan <
denilson.d...@gmail.com> wrote:

> me pueden enviar el codigo completo ? para hacer un login solo la
> interfqaz grafica sin nada de conexion a base de datos porfavor!
>
> El vie., 17 de abr. de 2020 a la(s) 00:00, Gavin Wiener (
> gavinwie...@gmail.com) escribió:
>
>> If you're serializing as JSON, that primary key is literally just integer
>> then, and the foreign key relationship requires an instance of that foreign
>> key. So you'll need to fetch an instance of the object first.
>>
>> I've had this issue before, that's how I resolved it.
>>
>> On Friday, April 17, 2020 at 1:51:05 PM UTC+8, shreehari Vaasistha L
>> wrote:
>>>
>>> i get this error when trying in your way:
>>>
>>> Cannot assign "2": "User.highest_degree" must be a "Degree" instance.
>>>
>>> On Thursday, April 16, 2020 at 5:31:07 PM UTC+5:30, Gavin Wiener wrote:

 Couldn't the User just have a ForeignKey on countries?

 On Thursday, April 16, 2020 at 12:52:07 PM UTC+8, shreehari Vaasistha L
 wrote:
>
> how can i use model x values as choices for model y ?
>
> for eg:
> class countries(models.Model):
>  country = models.CharField(max_length=200)
>
>  def __str__(self):
>  return self.country
>
> class User(AbstractUser):
>  """User model."""
>
>  username = None
>  full_name = models.CharField(_("Full Name"), max_length=50, default="Full
> Name")
>  country_choices = models.CharField(choices=countries
>
 --
>> 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/c563335e-cd3f-4204-9aec-6c098dc3a525%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/CALVb5jEr-MnU7Z_6x%2BD30RrHGT4zBVSCsRGK4eGpikLXR%2BRQow%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/CAB8U4xO_ca0qcuJsvBGVRWpU1ctvQUsdSiFSUwWqO-ys4gE47Q%40mail.gmail.com.


Interfaz Gráfica (Frontend)

2020-04-17 Thread Denilson Antonio Avellan
Hola comunidad estoy empezando con Django me parece super genial pero 
quiero empezar con las interfaces gráficas por ejemplo necesito ejemplos o 
plantillas de login. menus. vistas etc. y queria saber en que me pueden 
ayudar mandandome links donde me pueda guiar! 

Muchas Gracias..!!

-- 
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/df15c69c-d84f-45b9-9663-37d6b4b9ae69%40googlegroups.com.


Re: Models as choices

2020-04-17 Thread Denilson Antonio Avellan
me pueden enviar el codigo completo ? para hacer un login solo la
interfqaz grafica sin nada de conexion a base de datos porfavor!

El vie., 17 de abr. de 2020 a la(s) 00:00, Gavin Wiener (
gavinwie...@gmail.com) escribió:

> If you're serializing as JSON, that primary key is literally just integer
> then, and the foreign key relationship requires an instance of that foreign
> key. So you'll need to fetch an instance of the object first.
>
> I've had this issue before, that's how I resolved it.
>
> On Friday, April 17, 2020 at 1:51:05 PM UTC+8, shreehari Vaasistha L wrote:
>>
>> i get this error when trying in your way:
>>
>> Cannot assign "2": "User.highest_degree" must be a "Degree" instance.
>>
>> On Thursday, April 16, 2020 at 5:31:07 PM UTC+5:30, Gavin Wiener wrote:
>>>
>>> Couldn't the User just have a ForeignKey on countries?
>>>
>>> On Thursday, April 16, 2020 at 12:52:07 PM UTC+8, shreehari Vaasistha L
>>> wrote:

 how can i use model x values as choices for model y ?

 for eg:
 class countries(models.Model):
  country = models.CharField(max_length=200)

  def __str__(self):
  return self.country

 class User(AbstractUser):
  """User model."""

  username = None
  full_name = models.CharField(_("Full Name"), max_length=50, default="Full
 Name")
  country_choices = models.CharField(choices=countries

>>> --
> 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/c563335e-cd3f-4204-9aec-6c098dc3a525%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/CALVb5jEr-MnU7Z_6x%2BD30RrHGT4zBVSCsRGK4eGpikLXR%2BRQow%40mail.gmail.com.


Re: problem with admin panel

2020-04-17 Thread Andréas Kühne
This sounds like you are having problems with the static files - check so
that you have run "manage.py collectstatic" correctly and that the command
works.

Regards,

Andréas


Den fre 17 apr. 2020 kl 03:57 skrev Cristhian Heredia Claure <
cris94@gmail.com>:

>
> Hello everyone Sorry if it's not correct to post here this issue that I
> have... In a LINUX environment, after all configuration for my project,
> when I try to log in the admin site, the style of the page of the admin
> panel is well stylized, as it should be.
> But in the test that I did in a Windows environment (the same
> configuration), everything is correct, but the page of the administration
> panel does not have any style, why is this? I search in many forums but I
> could not find a solution. Thanks in advance.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c26e722d-69fd-4dd2-9e32-94f451cf8e0f%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/CAK4qSCeNcfNg7AjM3ztWqcBWYyE8FBf_wixAGRSJhvctVW6fyw%40mail.gmail.com.


reg: CUstomizing User model

2020-04-17 Thread 'Amitesh Sahay' via Django users
Hi, 
I am creating the user signup form with the help of "UserCreationForm" and 
"User" model. So, whatever came in-built is working fine for me, I am able to 
successfully create the sign up and form and able to authenticate. So far so 
good. 
Now, I am trying to add a new "phone" field in the existing User model as per 
my customization plan. 
1) So, as per the user model customization process I make the entries in the 
models.py
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver

class SignUp(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
Contact = models.TextField(max_length=500, blank=True)


@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
if created:
SignUp.objects.create(user=instance)

@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs):
instance.profile.save() 2) python manage.py makemigrations3) python 
manage.py migrate4) I added the newly defined model in my forms.py as below:
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
from django import forms
from  .models import SignUp

class SignUpForm(UserCreationForm): # Default signup page layout
email = forms.EmailField()
first_name = forms.CharField(max_length=100)
last_name = forms.CharField(max_length=100)

class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'email', 'password1', 
'password2')


class SignUpPage(UserCreationForm): # Newly added model
phone = forms.CharField(max_length=10)
class Meta:
model = User
fields = ('phone', )But I am not sure if I needed to create a separate 
class for that, or I should add the extra field in the same default sign up 
page layout. Below is my views.py for the default layout
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login, logout
from django.contrib import messages
#from django.contrib.auth.forms import UserCreationForm
from .forms import SignUpForm, SignUp

def home(request):
   return render(request, 'authenticate\home.html', {})

def login_user(request):
   if request.method == 'POST':
  username = request.POST['username']
  password = request.POST['password']
  user = authenticate(request, username=username, password=password)
  if user is not None:
 login(request, user)
 messages.success(request, ('login success'))
 return redirect('home')
  else:
 messages.success(request, ('error while login, please try again'))
 return redirect('login')
   else:
  return render(request, 'authenticate\login.html', {})

def logout_user(request):
   logout(request)
   messages.success(request, ('logout successful'))
   return redirect('home')


def register_user(request):
   if request.method == "POST":
  form = SignUpForm(request.POST)
  if form.is_valid():
 form.save()
 username = form.cleaned_data['username']
 password = form.cleaned_data['password1']
 user = authenticate(request, username=username, password=password)
 login(request, user)
 messages.success(request, ('Registration successful'))
 return redirect('home')
  else:
 form = SignUpForm()
  return render(request, 'authenticate\\register.html', context={'form': 
form})

As one can see that I have imported the required class from forms.py, but I am 
not able to recognize the place where I can call it in "register_user" in 
views.py.Please help. Also correct if I have done anything wrong.

Regards,
Amitesh 

-- 
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/1470388256.1447595.1587121976643%40mail.yahoo.com.


Re: Cannot Redirect to other page

2020-04-17 Thread pui hei Li
Thank you so much, I have fixed the problem, now I can redirect to the 
pages I want.

*morse_logs/game2.html*

{% extends "morse_logs/base.html" %}

{% block content %}
GAME 2

GAME 2
2 + 2 = ?

{% csrf_token %}




{% endblock content %}


*morse_logs/views.html*

@login_required()
def game2(request):
"""The Game2 page"""
if request.method == "GET":
return render(request, 'morse_logs/game2.html')
elif request.method == "POST":
if request.user and not request.user.is_anonymous:
user = request.user

user_score, created = userScore.objects.get_or_create(user=user)

ans2 = request.POST.get('ans2', '') #fetch the POST data from template
if ans2 == '':
ans2 = 0

ans2 = int(ans2)
if ans2 == 4:
# user's score declared in model increase 5points
# display correct and 5 points added to user
user_score.score += 5
user_score.save()
return redirect(reverse('morse_logs:correct'))
else:
# user's score declared in model has no point
# display incorrect and 0 point added to user
return redirect(reverse('morse_logs:incorrect'))




On Wednesday, April 15, 2020 at 8:22:35 PM UTC+8, pui hei Li wrote:
>
> I am writing a view that retrieve an answer from game2.html, then check 
> the answer; if the answer is correct, the view will redirect user to 
> correct.html, if the answer is incorrect, then user will be redirected to 
> incorrect.html. 
>
> The problem now is after clicking the submit button, user won't be 
> redirected. And after clicking the submit button, the url changed from 
> localhost:8000/game2 to 
> http://localhost:8000/game2/?ans2=4=Submit 
>
> It seems the view is not verifying the answer, and it is also redirecting 
> user to anywhere.
>
> How do I solve it?
>
> *morse_logs/views.py*
>
> @login_required()
> def game2(request):
> """The Game2 page"""
> if request.user and not request.user.is_anonymous:
> user = request.user
>
> def verifyGame2(val1):
> user_score, created = userScore.objects.get_or_create(user=user)
>
> if val1 == 4:
> # user's score declared in model increase 5points
> # display correct and 5 points added to user
> user_score.score += 5
> user_score.save()
> return redirect(reverse('morse_logs:incorrect'))
> else:
> # user's score declared in model has no point
> # display incorrect and 0 point added to user
> return redirect(reverse('morse_logs:incorrect'))
>
>
> ans2 = request.GET.get('ans2', '')
> if ans2 == '':
> ans2 = 0
>
> verifyGame2(int(ans2))
>
> return render(request, 'morse_logs/game2.html')
>
>
> *morse_logs/game2.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> GAME 2
> 
> GAME 2
> 2 + 2 = ?
> 
> 
> 
> 
> 
> {% endblock content %}
>
>
> *morse_logs/correct.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> Correct!
> 
> Congratulations! Your answer is CORRECT!
> 
> {% endblock content %}
>
>
> *morse_logs/incorrect.html*
>
> {% extends "morse_logs/base.html" %}
>
> {% block content %}
> Inorrect...
> 
> Unfortunately! Your answer is Incorrect!
> 
> {% endblock content %}
>
>
> *morse_logs/urls.py*
>
> from django.urls import path, include
> from morse_logs import views
>
> app_name = 'morse_logs'
>
> urlpatterns = [
> #The path() function is passed four arguments, two required: route and 
> view, and two optional: kwargs, and name.
> # Home Page
> path(r'', views.index, name='index'),
> # Page that shows all topics
> path(r'topics/', views.topics, name='topics'),
> path(r'cipher/', views.cipher, name='cipher'),
> path(r'decipher/', views.decipher, name='decipher'),
> path(r'tutorialIndex/', views.tutorialIndex, name='tutorialIndex'),
> path(r'gameDirectory/', views.gameDirectory, name='gameDirectory'),
> path(r'correct/', views.correct, name='correct'),
> path(r'incorrect/', views.incorrect, name='incorrect'),
> path(r'game1/', views.game1, name='game1'),
> path(r'game2/', views.game2, name='game2'),
>
> ]
>
>

-- 
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/64d9a376-ac00-4f2d-858d-04c63e8826d6%40googlegroups.com.


Re: Models as choices

2020-04-17 Thread Gavin Wiener
If you're serializing as JSON, that primary key is literally just integer 
then, and the foreign key relationship requires an instance of that foreign 
key. So you'll need to fetch an instance of the object first.

I've had this issue before, that's how I resolved it.

On Friday, April 17, 2020 at 1:51:05 PM UTC+8, shreehari Vaasistha L wrote:
>
> i get this error when trying in your way:
>
> Cannot assign "2": "User.highest_degree" must be a "Degree" instance.
>
> On Thursday, April 16, 2020 at 5:31:07 PM UTC+5:30, Gavin Wiener wrote:
>>
>> Couldn't the User just have a ForeignKey on countries?
>>
>> On Thursday, April 16, 2020 at 12:52:07 PM UTC+8, shreehari Vaasistha L 
>> wrote:
>>>
>>> how can i use model x values as choices for model y ?
>>>
>>> for eg:
>>> class countries(models.Model):
>>>  country = models.CharField(max_length=200)
>>>
>>>  def __str__(self):
>>>  return self.country 
>>>
>>> class User(AbstractUser):
>>>  """User model."""
>>>
>>>  username = None
>>>  full_name = models.CharField(_("Full Name"), max_length=50, default="Full 
>>> Name") 
>>>  country_choices = models.CharField(choices=countries
>>>
>>

-- 
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/c563335e-cd3f-4204-9aec-6c098dc3a525%40googlegroups.com.