Monday, May 31, 2021

Inlined hierarchy models in django admin site.

class Patient(models.Model):
     patient_id = models.CharField(max_length=60)


class PatientVaccineStatus(models.Model):
      patient = models.ForeignKey(Patient, related_name="patient_vaccine_status")

class Vaccine(models.Model)
     vaccine = models.ForeignKey(PatientVaccineStatus, related_name="vaccine_status")
 
..................................................................

Is there any way to merged all the tables in a single table of patient.

I successfully merge, PatientVaccineStatus table with Patient table, but Vaccine's table is not merging with the Patient. 

how can this hierarchy be merged in a single table.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/57aac480-cb53-4fbe-a3bd-8766cd7a5b82n%40googlegroups.com.

Re: How does django-admin work?

Welcome to Django!

Django does not add django-admin to your path. Rather, when Django is installed it (sometimes) happens to be installed into a place which is already in your path. Otherwise, you need to add it to your path or use a packaging system such as anaconda which helps do that for you.

startproject simply copies a set of files to your directories, filling in a few details and changing the file names to match what you want to create since you give it the name of your new project.

hth

- Tom

On May 31, 2021, at 5:43 PM, J Lee <ljin0906@gmail.com> wrote:

I'm new to Django, and I've just been dazzled by the magic of Django. My main question is how does Django add django-admin to my path automatically and how does django-admin startproject create my files?

It may be waaaay over my head, but I welcome any and all response. I would like to learn from this. 

Thank you.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5b022968-ac51-4e49-873d-f9a3b7b88ba4n%40googlegroups.com.

SVG widget for the Admin

I collect the svg source for an image from a public API and store it in
a models.TextField. I have no difficulty displaying it in a normal view
and my own template. Nothing special, it just emerges. I don't even need
a 'safe' filter.

However, I really want to display such images in the Admin. At this
stage all it displays is the svg source.

What is the correct way to make the image appear in the Admin?

Do I need a special field inheriting from TextField? Do I need a special
widget? Is there a way to mark admin field values as safe?

Thanks for any hints

Mike

--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Just
ask and I'll send it to you. Your email software can handle signing.


--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b8ec5d1f-950f-c3cf-2490-e52e75035660%40dewhirst.com.au.

How does django-admin work?

I'm new to Django, and I've just been dazzled by the magic of Django. My main question is how does Django add django-admin to my path automatically and how does django-admin startproject create my files?

It may be waaaay over my head, but I welcome any and all response. I would like to learn from this. 

Thank you.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5b022968-ac51-4e49-873d-f9a3b7b88ba4n%40googlegroups.com.

Using jsonb_array_elements with querysets

I'm trying to use the jsonb_array_elements Postgres function with querysets but I am running into issues.

I defined a custom Func as:

class JsonbArrayElements(Func):
    function = 'jsonb_array_elements'

While this does seem to result in proper sql when used in an annotation, the issue comes when I try to filter on the new field. Postgres doesn't allow you to use the new field in a where clause without using a subquery first.

The query that I am trying to write is equivalent to:

select *
from (
select id, jsonb_array_elements(json_data->'some_array') as elem
from foo as foo1
union
select id, jsonb_array_elements(json_data->'other_array') as elem
from foo as foo2
) as foo_w_elems
where (elem->>'subfield')::int in (
select id
from bar
where expires_at >= CURRENT_TIMESTAMP
)

Unfortunately, even with Django's subquery support, I have been unable to get a query to add the where clause to the results of a subquery.

My issue seems related to https://code.djangoproject.com/ticket/24462, but was curious if there is a way to use and filter jsonb_array_elements results in Django today without using raw sql?

I'm also investigating using the low-level query API directly, but have run into some issues so far.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/68017f88-bbcc-43be-96ae-c7a3cd802d0an%40googlegroups.com.

Re: Help with a huge database query.

If I use the  values()  or  values_list()  the request in database has a long waiting time and some time I also got a  MemoryError (because 4GB RAM is not enough).
My examples:

Apple.objects.select_related('Orange').filter(state='fresh').values_list(
                               # Fields I don't want:
                               'field1',
                               'field2',
                               'field3'
                               # ..... ,
                               'field37'
                               )

( yes I want 37 different values ).

I also try with  .only()  with very nice response time, but in the end I will get all the fields. For example:
temp = Apple.objects.select_related('Orange').filter(state='fresh').only(
                               'field1',
                               'field2',
                               'field3' )

temp_json = serializers.serialize('json', temp)
return HttpResponse(temp_json, content_type='application/json')

it returns me all the fields! Not only the 'field2', 'field2' and 'field3'.
Could you explain me why ?


Finally, I also tried to run a query with  raw()  but the response time is disappointing.


‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Friday, May 28, 2021 2:13 AM, David Nugent <davidn@uniquode.io> wrote:

I think a better approach to using QuerySet.defer() is to use .values() instead, explicitly specifying which fields you need to export.

Just FYI rest_framework handles this out of the box and provides an API to specify not only which fields to export but filters as well.

Regards
/d


On Fri, May 28, 2021 at 8:10 AM 'odrzen' via Django users <django-users@googlegroups.com> wrote:
Hello Django community o/

I want to create a API call in order to get all data from a specific model ( table ) - but I want to exclude-remove only specific fields from this.
So, I try to find a right way to execute this difficult and "heavy" query/request with a efficient way.
This is what I have achieved so far:

```
#from django.http import HttpResponse, HttpResponseRedirect, JsonResponse
#from django.core import serializers
from apples.models import Apple
from oranges.models import Orange

published_fruits =  Apple.objects.select_related('Orange').filter(state='published').defer(
                               # Fields I don't want:
                               'field1',
                               'field2',
                               'field3'
                               )

So, I have the following results:
[
  {
    "model": "apples.apple",
    "pk": "5326t236-8415-48f4-89e5-1789vc9of442",
    "fields": {
      "id": "apple-type1",
      "name": "Brazil",
      ".....": "....",
      "exports ": []
    }
  },
  { ... }
  {
    "model": "apples.apple",
    "pk": "6435673472-fret2-523t-523t-d41159t23432213",
    "fields": {
      "id": "apple-type2",
      "name": "India",
            ".....": "....",
      "exports ": []
    }
  }
]
```


My proble is :
1. The fields who I don't want (exclude), finally I got it.
2. I want to directly pass all this response to a JSON http output for the users and I have it with the following way:
```
json_response = serializers.serialize('json', published_fruits)
return HttpResponse(json_response, content_type='application/json')
```
I get all the respone in JSON, but ( as you can see above ) with the following stracture:
```
  {
    "model": "apples.apple",
    "pk": "6435673472-fret2-523t-523t-d41159t23432213",
    "fields": {
      "id": "apple-type2",
      "name": "India",
            ".....": "....",
      "exports ": []
    }
  }
```

Please, could you help me to avoid the following part from each record  :
```
    "model": "apples.apple",
    "pk": "6435673472-fret2-523t-523t-d41159t23432213",
    "fields": {
```
from the JSON ?

Thank you very much 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+unsubscribe@googlegroups.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+unsubscribe@googlegroups.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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/mlI7MqIhUIK5iaGcpHMCV2te7ixZ7sczFPnrDUv_j8MmyeKVWZe1Z2qdWCJNhxBqIVAr3B2KtWWoEEQKKR9WA6EB27-gEvMg0eCnO2ZcPd0%3D%40protonmail.com.

Re: IntegrityError at /userapp/detail/ NOT NULL constraint failed: userapp_profile.babyinfo_id

Hey bro,
i try to combine  two model forms in single view django views  
but i dnt knw how to work with this please check my below code and help me!

On Monday, May 31, 2021 at 11:15:29 PM UTC+5:30 Kasper Laudrup wrote:
On 31/05/2021 18.46, Hugh Frost wrote:
> Hii all,
> I hv been struck in last 4 days please fix this error , i'm new to django
>

Instead of telling people how many days you've spent trying to fix the
error, try spend some time on explaining what you've spent the days on
doing and what you're trying to achieve.

That will greatly improve your chances of getting help.

Kind regards,

Kasper Laudrup


> --
> 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
> <mailto:django-users...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c753a468-0b45-4266-9094-213719986069n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/c753a468-0b45-4266-9094-213719986069n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3c8e630f-103b-4612-9cb8-955950953a7bn%40googlegroups.com.

Re: IntegrityError at /userapp/detail/ NOT NULL constraint failed: userapp_profile.babyinfo_id

On 31/05/2021 18.46, Hugh Frost wrote:
> Hii all,
> I hv been struck in last 4 days please fix this error , i'm new to django
>

Instead of telling people how many days you've spent trying to fix the
error, try spend some time on explaining what you've spent the days on
doing and what you're trying to achieve.

That will greatly improve your chances of getting help.

Kind regards,

Kasper Laudrup


> --
> 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+unsubscribe@googlegroups.com
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c753a468-0b45-4266-9094-213719986069n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/c753a468-0b45-4266-9094-213719986069n%40googlegroups.com?utm_medium=email&utm_source=footer>.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e46ce62f-e92a-8efa-c49e-11c8036af6ff%40stacktrace.dk.

Re: CSS not linking with HTML

You are welcome))

On Mon, 31 May 2021, 6:44 pm sukhy gill, <sukhy.gill1989@gmail.com> wrote:
Thanku so much all of you for your valuable guidance to me 🙏🙏🙏🙂🙂

On Mon, May 31, 2021, 21:07 Chelsea Fan <allaberdi16yazhanow@gmail.com wrote:
Good luck 👍👍👍👍

On Mon, 31 May 2021, 6:31 pm sukhy gill, <sukhy.gill1989@gmail.com> wrote:
I deleted my project and will start project again from begining and then will let you know the progress.
Regards

On Sun, May 30, 2021, 16:48 Mehdi Ismail <mehdizprofile@gmail.com wrote:
you want to mention (provide screenshot) of the error?

On Sunday, 30 May 2021 at 09:14:22 UTC+5:30 sukhy.g...@gmail.com wrote:
Getting error while using using command python manage.py collectstatic
Regarda

On Sat, May 29, 2021, 21:23 Mehdi Ismail <mehdiz...@gmail.com wrote:
python manage.py collectstatic 


try that... and update
On Saturday, 29 May 2021 at 20:44:48 UTC+5:30 sukhy.g...@gmail.com wrote:
Project Folder ➡️static ➡️css➡️style.css➡️

On Sat, May 29, 2021, 19:16 Fabiano Leite <fabiano....@gmail.com wrote:

Where is located your 'css/style.css';
Em sábado, 29 de maio de 2021 às 10:04:50 UTC-3, sukhy.g...@gmail.com escreveu:
No dear

On Sat, May 29, 2021, 18:29 Chelsea Fan <allaberdi...@gmail.com wrote:
Is it working now?

On Sat, 29 May 2021, 3:40 pm lalit suthar, <sutharl...@gmail.com> wrote:
read this https://docs.djangoproject.com/en/2.2/intro/tutorial06/ and check how you are giving paths. Also after loading the page on your browser go to "View Page Source" and click on the CSS file link and check if the file is opening or not.

On Saturday, 29 May 2021 at 17:57:21 UTC+5:30 sukhy.g...@gmail.com wrote:
Yes Sir,There was no mistake in code. Code problem was only in mail content actually code was correct as instruction given by Aniket Sir

Regards


On Sat, May 29, 2021, 13:14 lalit suthar <sutharl...@gmail.com wrote:
have you checked Aniket's answer?

On Saturday, 29 May 2021 at 11:09:07 UTC+5:30 sukhy.g...@gmail.com wrote:
Done Sir, but not working

On Sat, May 29, 2021, 10:50 Venu Gopal <reachme...@gmail.com wrote:
In Firefox ---- Goto Preferences ---> Choose Privacy and Security ---> scroll down until you get cookies and site data --> clear data
Chrome ---- Goto Settings ---> Choose Privacy and Security ---> select cookies and other site data --> select see all cookies and site data --> Remove all

On Sat, May 29, 2021 at 9:50 AM sukhy gill <sukhy.g...@gmail.com> wrote:
@Venu Gopal

No Sir, I don't know, how to do this.

May I know Sir, how to do the same?

Regards

On Sat, May 29, 2021, 09:41 Venu Gopal <reachme...@gmail.com wrote:
Hi, Have you tried deleting existing cache and cookies in the browser?

On Sat, May 29, 2021 at 12:08 AM sukhy gill <sukhy.g...@gmail.com> wrote:
Dear Frnds
                I am unable to  link CSS with HTML
HTML working but CSS not working inside the .html file with the help of LINK in <head> tag 

I am using thefollowings:-
Setting.py -  STATICFILES_DIRS=[os.path.join(BASE_DIR, 'static'),]
HTML- {% load static %}
<Link rel="stylesheet" href="{% static 'css/syle.css %} />
 
Regards

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3ca2aba0-a58f-4298-b248-16c51bdf90a6n%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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOhYkiyqw8k5zCL1XZo9U%2BY9_JR57p55xf-%3DtFf6Fa4HVskPSw%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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJ8btZave0utnYTAcrxafKes6sUZ3%2BX%2B0v1EGs-pJSF1%2BT4qxw%40mail.gmail.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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6270c1f5-a1d9-4904-a5ed-85e21030b894n%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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3e26aaf1-212c-42fe-b7fe-b770dac85e4en%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJ8btZYb461qqot%2BMNRB4bNq4qcdAVWGni_uhfo1Yr6hzmJ0oA%40mail.gmail.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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJwZndcDCN5U7SAzYpuq%2BtPM0QCQz0XKw74jQsLvnPKXKUzLNw%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJ8btZaTm3UwH%3D6YKyC1LzXWtdiEzuqEGhm3XgoXOGFNH%2BVW1w%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJwZndeBykTGKzXBYT94dV-EqwyRzWKoXRHFM5QhDDqtSFC8VQ%40mail.gmail.com.

IntegrityError at /userapp/detail/ NOT NULL constraint failed: userapp_profile.babyinfo_id

from django.db import models
from django.urls import reverse
from django.contrib.auth.models import User

from PIL import Image
# from package.models import Package
# from .models import BabyInfo,Profile
# from user_profile.models import BabyInfo
# Create your models here.
class UserOTP(models.Model):
user = models.ForeignKey(User, on_delete = models.CASCADE)
time_st = models.DateTimeField(auto_now = True)
otp = models.SmallIntegerField()

def upload_profile_to(instance,filename):
return f'profile_picture/{instance}/{filename}'

class BabyInfo(models.Model):
MALE = 'male'
FEMALE = 'female'
BOTH = 'both'
GENDER = (
('MALE','Male'),
('FEMALE','Female'),
('BOTH','both'),
)

Y='yes'
N='no'
CHOICES = (
('Y', 'Yes'),
('N', 'No'),
)
born_status = models.CharField(max_length=1, choices=CHOICES)
gender = models.CharField(max_length=10, choices=GENDER, verbose_name="gender")
story_name = models.CharField(max_length=100)
baby_date = models.DateField()
profile_pic = models.ImageField(upload_to = upload_profile_to, default = 'defaults/profile_pic.jpg')
# package=models.ForeignKey(Package,on_delete=models.CASCADE)
created = models.DateTimeField(verbose_name=('Created'),auto_now_add=True)
updated = models.DateTimeField(verbose_name=('Updated'),auto_now=True)

class Meta:
verbose_name = ('BabyInfo')
verbose_name_plural = ('BabyInfos')
ordering = ['-created']

def __str__(self):
return self.story_name


class Profile(models.Model):
user = models.OneToOneField(User, on_delete = models.CASCADE,)
profile_pic = models.ImageField(upload_to = upload_profile_to, null=True)
# cover_image = models.ImageField(upload_to = 'upload_cover_to', null = True, default= 'defaults/cover_image.jpg')
name=models.CharField(max_length=250)
mail_id=models.EmailField()
relationship=models.CharField(max_length=100)
phone_no=models.IntegerField()
is_lead_user=models.BooleanField(('Is LEAD USER'),help_text='button to toggle employee lead and aditional',default=False)
babyinfo=models.ForeignKey(BabyInfo,on_delete=models.CASCADE,null=True)
created = models.DateTimeField(verbose_name=('Created'),auto_now_add=True,null=True)
updated = models.DateTimeField(verbose_name=('Updated'),auto_now=True,null=True)

class Meta:
verbose_name = ('Profile')
verbose_name_plural = ('Profiles')
ordering = ['-created']

def __str__(self):
return self.mail_id

def save(self, *args, **kwargs):
super().save(*args, **kwargs)

img = Image.open(self.profile_pic.path)
if img.height > 300 or img.width > 300:
output_size = (300, 300)
img.thumbnail(output_size)
img.save(self.profile_pic.path)

img2 = Image.open(self.cover_image.path)
if img2.height > 500 or img2.width > 500:
output_size = (500, 500)
img2.thumbnail(output_size)
img2.save(self.cover_image.path)
from django.shortcuts import render
from django.shortcuts import redirect
from django.urls import reverse
from django.shortcuts import get_object_or_404
from django.http import HttpResponseRedirect, HttpResponse
from django import forms
# Create your views here.
# from .forms import Profile
from userapp.models import BabyInfo,Profile,UserOTP
from userapp.forms import BabyForm1,BabyForm2


from django.contrib import messages
import random
from .forms import SignUpForm
from django.contrib.auth.models import User
from django.core.mail import send_mail
from django.conf import settings
from django.http import HttpResponse, Http404, JsonResponse
from django.contrib.auth.forms import AuthenticationForm, PasswordChangeForm
from django.contrib.auth import authenticate, login
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt
from django.core import serializers
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger


def page(request):
return render(request,'userapp_temp/landing_page.html')

def home(request):
return render(request,'userapp_temp/home.html',)

# def index(request):
# return render(request, 'userapp_temp/index.html', {'title':'index'})

# def login(request):
# return render(request,'userapp_temp/login.html')
#
# def register(request):
# return render(request,'userapp_temp/signup.html')

def profile(request):
return render(request,'userapp_temp/profile.html')


#########################(BABY_PROFILE)#########################################
def detail(request):
if request.method == 'POST':
baby_form1 = BabyForm1(data=request.POST)
baby_form2 = BabyForm2(data=request.POST)

if baby_form1.is_valid() and baby_form2.is_valid():
baby1 = baby_form1.save(commit=False)
baby1.save()
print(baby1)

baby2 = baby_form2.save(commit=False)
baby2.baby1 = baby1
baby2.save()
print(baby2)

baby_form1 = BabyForm1()
baby_form2 = BabyForm2()
context = {'baby_form1':baby_form1, 'baby_form2':baby_form2,}
return render(request,'userapp_temp/profile.html', context)



# registered = False
#
#
#
# if request.method == "POST":
# baby_form1 = BabyForm1(data=request.POST)
#
#
# if baby_form1.is_valid():
# baby1 = baby_form1.save(commit=True)
# baby_id = baby1.id
#
# print(baby1.id)
#
#
# # babyinfo = BabyInfo.objects.get(pk=103)
# # print(babyinfo)
# baby_form2 = BabyForm2(data=request.POST)
# print(baby_form2)
# # baby2 = baby_form2.save()
# if baby_form2.is_valid():
# print("form2 start")
# baby2 = baby_form2.save(commit=False)
# baby2.babyinfo_id=baby_id
# baby2.user_id=8
# baby2.save()
# # baby2.name = baby1
#
#
# registered =True
#
# else:
# print(baby_form1.errors,baby_form2.errors)
#
#
# else:
# return render(request,'userapp_temp/landing_page.html')
##################################

def signup(request):
if request.method == 'POST':
get_otp = request.POST.get('otp') #213243 #None

if get_otp:
get_usr = request.POST.get('usr')
usr = User.objects.get(username=get_usr)
if int(get_otp) == UserOTP.objects.filter(user = usr).last().otp:
usr.is_active = True
usr.save()
messages.success(request, f'Account is Created For {usr.username}')
return redirect('userapp:login')
else:
messages.warning(request, f'You Entered a Wrong OTP')
return render(request, 'userapp_temp/signup.html', {'otp': True, 'usr': usr})

form = SignUpForm(request.POST)
if form.is_valid():
form.save()
username = form.cleaned_data.get('username')
name = form.cleaned_data.get('name').split(' ')

usr = User.objects.get(username=username)
usr.email = username
usr.first_name = name[0]
if len(name) > 1:
usr.last_name = name[1]
usr.is_active = False
usr.save()
usr_otp = random.randint(100000, 999999)
UserOTP.objects.create(user = usr, otp = usr_otp)

mess = f"Hello {usr.first_name},\nYour OTP is {usr_otp}\nThanks!"

send_mail(
"Welcome to KuttyStory - Verify Your Email",
mess,
settings.EMAIL_HOST_USER,
[usr.email],
fail_silently = False
)

return render(request, 'userapp_temp/signup.html', {'otp': True, 'usr': usr})


else:
form = SignUpForm()

return render(request, 'userapp_temp/signup.html', {'form':form})


def resend_otp(request):
if request.method == "GET":
get_usr = request.GET['usr']
if User.objects.filter(username = get_usr).exists() and not User.objects.get(username = get_usr).is_active:
usr = User.objects.get(username=get_usr)
usr_otp = random.randint(100000, 999999)
UserOTP.objects.create(user = usr, otp = usr_otp)
mess = f"Hello {usr.first_name},\nYour OTP is {usr_otp}\nThanks!"

send_mail(
"Welcome to KuttyStory - Verify Your Email",
mess,
settings.EMAIL_HOST_USER,
[usr.email],
fail_silently = False
)
return HttpResponse("Resend")

return HttpResponse("Can't Send ")


def login_view(request):
if request.user.is_authenticated:
return redirect('userapp:login')
if request.method == 'POST':
get_otp = request.POST.get('otp') #213243 #None

if get_otp:
get_usr = request.POST.get('usr')
usr = User.objects.get(username=get_usr)
if int(get_otp) == UserOTP.objects.filter(user = usr).last().otp:
usr.is_active = True
usr.save()
login(request, usr)
return redirect('userapp:login')
else:
messages.warning(request, f'You Entered a Wrong OTP')
return render(request, 'userapp_temp/login.html', {'otp': True, 'usr': usr})


usrname = request.POST['username']
passwd = request.POST['password']

user = authenticate(request, username = usrname, password = passwd) #None
if user is not None:
login(request, user)
return redirect('userapp:login')
elif not User.objects.filter(username = usrname).exists():
messages.warning(request, f'Please enter a correct username and password. Note that both fields may be case-sensitive.')
return redirect('userapp:login')
elif not User.objects.get(username=usrname).is_active:
usr = User.objects.get(username=usrname)
usr_otp = random.randint(100000, 999999)
UserOTP.objects.create(user = usr, otp = usr_otp)
mess = f"Hello {usr.first_name},\nYour OTP is {usr_otp}\nThanks!"

send_mail(
"Welcome to KuttyStory - Verify Your Email",
mess,
settings.EMAIL_HOST_USER,
[usr.email],
fail_silently = False
)
return render(request, 'userapp_temp/login.html', {'otp': True, 'usr': usr})
else:
messages.warning(request, f'Please enter a correct username and password. Note that both fields may be case-sensitive.')
return redirect('userapp:login')

form = AuthenticationForm()
return render(request, 'userapp_temp/login.html', {'form': form})
from django import forms
from django.forms import ModelForm
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm
from django.core.exceptions import ValidationError
from .models import BabyInfo,Profile

from django.contrib.auth.forms import UserCreationForm

class BabyForm1(forms.ModelForm):
class Meta:
model = BabyInfo
fields = ['story_name', 'baby_date', 'profile_pic']
labels = {
'story_name': 'story_name',
'baby_date': 'baby_date',
'profile_pic': 'profile_pic'
}

class BabyForm2(forms.ModelForm):
class Meta:
model = Profile
fields = ['name', 'mail_id', 'relationship']
labels = {
'name': 'name',
'mail_id': 'mail_id',
'relationship': 'relationship'
}




# class UserRegisterForm(UserCreationForm):
# email = forms.EmailField()
# phone_no = forms.CharField(max_length = 20)
# first_name = forms.CharField(max_length = 20)
# last_name = forms.CharField(max_length = 20)
# class Meta:
# model = User
# fields = ['username', 'email', 'phone_no', 'password1', 'password2']


class SignUpForm(UserCreationForm):
name = forms.CharField(label = ("Username"))
username = forms.EmailField(label = ("Email"))

class Meta:
model = User
fields = ('name', 'username', 'password1', 'password2')
Hii all,
I hv been struck in last 4 days please fix this error , i'm new to django

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c753a468-0b45-4266-9094-213719986069n%40googlegroups.com.

Re: CSS not linking with HTML

Thanku so much all of you for your valuable guidance to me 🙏🙏🙏🙂🙂

On Mon, May 31, 2021, 21:07 Chelsea Fan <allaberdi16yazhanow@gmail.com wrote:
Good luck 👍👍👍👍

On Mon, 31 May 2021, 6:31 pm sukhy gill, <sukhy.gill1989@gmail.com> wrote:
I deleted my project and will start project again from begining and then will let you know the progress.
Regards

On Sun, May 30, 2021, 16:48 Mehdi Ismail <mehdizprofile@gmail.com wrote:
you want to mention (provide screenshot) of the error?

On Sunday, 30 May 2021 at 09:14:22 UTC+5:30 sukhy.g...@gmail.com wrote:
Getting error while using using command python manage.py collectstatic
Regarda

On Sat, May 29, 2021, 21:23 Mehdi Ismail <mehdiz...@gmail.com wrote:
python manage.py collectstatic 


try that... and update
On Saturday, 29 May 2021 at 20:44:48 UTC+5:30 sukhy.g...@gmail.com wrote:
Project Folder ➡️static ➡️css➡️style.css➡️

On Sat, May 29, 2021, 19:16 Fabiano Leite <fabiano....@gmail.com wrote:

Where is located your 'css/style.css';
Em sábado, 29 de maio de 2021 às 10:04:50 UTC-3, sukhy.g...@gmail.com escreveu:
No dear

On Sat, May 29, 2021, 18:29 Chelsea Fan <allaberdi...@gmail.com wrote:
Is it working now?

On Sat, 29 May 2021, 3:40 pm lalit suthar, <sutharl...@gmail.com> wrote:
read this https://docs.djangoproject.com/en/2.2/intro/tutorial06/ and check how you are giving paths. Also after loading the page on your browser go to "View Page Source" and click on the CSS file link and check if the file is opening or not.

On Saturday, 29 May 2021 at 17:57:21 UTC+5:30 sukhy.g...@gmail.com wrote:
Yes Sir,There was no mistake in code. Code problem was only in mail content actually code was correct as instruction given by Aniket Sir

Regards


On Sat, May 29, 2021, 13:14 lalit suthar <sutharl...@gmail.com wrote:
have you checked Aniket's answer?

On Saturday, 29 May 2021 at 11:09:07 UTC+5:30 sukhy.g...@gmail.com wrote:
Done Sir, but not working

On Sat, May 29, 2021, 10:50 Venu Gopal <reachme...@gmail.com wrote:
In Firefox ---- Goto Preferences ---> Choose Privacy and Security ---> scroll down until you get cookies and site data --> clear data
Chrome ---- Goto Settings ---> Choose Privacy and Security ---> select cookies and other site data --> select see all cookies and site data --> Remove all

On Sat, May 29, 2021 at 9:50 AM sukhy gill <sukhy.g...@gmail.com> wrote:
@Venu Gopal

No Sir, I don't know, how to do this.

May I know Sir, how to do the same?

Regards

On Sat, May 29, 2021, 09:41 Venu Gopal <reachme...@gmail.com wrote:
Hi, Have you tried deleting existing cache and cookies in the browser?

On Sat, May 29, 2021 at 12:08 AM sukhy gill <sukhy.g...@gmail.com> wrote:
Dear Frnds
                I am unable to  link CSS with HTML
HTML working but CSS not working inside the .html file with the help of LINK in <head> tag 

I am using thefollowings:-
Setting.py -  STATICFILES_DIRS=[os.path.join(BASE_DIR, 'static'),]
HTML- {% load static %}
<Link rel="stylesheet" href="{% static 'css/syle.css %} />
 
Regards

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3ca2aba0-a58f-4298-b248-16c51bdf90a6n%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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOhYkiyqw8k5zCL1XZo9U%2BY9_JR57p55xf-%3DtFf6Fa4HVskPSw%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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJ8btZave0utnYTAcrxafKes6sUZ3%2BX%2B0v1EGs-pJSF1%2BT4qxw%40mail.gmail.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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6270c1f5-a1d9-4904-a5ed-85e21030b894n%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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3e26aaf1-212c-42fe-b7fe-b770dac85e4en%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJ8btZYb461qqot%2BMNRB4bNq4qcdAVWGni_uhfo1Yr6hzmJ0oA%40mail.gmail.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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJwZndcDCN5U7SAzYpuq%2BtPM0QCQz0XKw74jQsLvnPKXKUzLNw%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJ8btZaTm3UwH%3D6YKyC1LzXWtdiEzuqEGhm3XgoXOGFNH%2BVW1w%40mail.gmail.com.

Re: CSS not linking with HTML

Good luck 👍👍👍👍

On Mon, 31 May 2021, 6:31 pm sukhy gill, <sukhy.gill1989@gmail.com> wrote:
I deleted my project and will start project again from begining and then will let you know the progress.
Regards

On Sun, May 30, 2021, 16:48 Mehdi Ismail <mehdizprofile@gmail.com wrote:
you want to mention (provide screenshot) of the error?

On Sunday, 30 May 2021 at 09:14:22 UTC+5:30 sukhy.g...@gmail.com wrote:
Getting error while using using command python manage.py collectstatic
Regarda

On Sat, May 29, 2021, 21:23 Mehdi Ismail <mehdiz...@gmail.com wrote:
python manage.py collectstatic 


try that... and update
On Saturday, 29 May 2021 at 20:44:48 UTC+5:30 sukhy.g...@gmail.com wrote:
Project Folder ➡️static ➡️css➡️style.css➡️

On Sat, May 29, 2021, 19:16 Fabiano Leite <fabiano....@gmail.com wrote:

Where is located your 'css/style.css';
Em sábado, 29 de maio de 2021 às 10:04:50 UTC-3, sukhy.g...@gmail.com escreveu:
No dear

On Sat, May 29, 2021, 18:29 Chelsea Fan <allaberdi...@gmail.com wrote:
Is it working now?

On Sat, 29 May 2021, 3:40 pm lalit suthar, <sutharl...@gmail.com> wrote:
read this https://docs.djangoproject.com/en/2.2/intro/tutorial06/ and check how you are giving paths. Also after loading the page on your browser go to "View Page Source" and click on the CSS file link and check if the file is opening or not.

On Saturday, 29 May 2021 at 17:57:21 UTC+5:30 sukhy.g...@gmail.com wrote:
Yes Sir,There was no mistake in code. Code problem was only in mail content actually code was correct as instruction given by Aniket Sir

Regards


On Sat, May 29, 2021, 13:14 lalit suthar <sutharl...@gmail.com wrote:
have you checked Aniket's answer?

On Saturday, 29 May 2021 at 11:09:07 UTC+5:30 sukhy.g...@gmail.com wrote:
Done Sir, but not working

On Sat, May 29, 2021, 10:50 Venu Gopal <reachme...@gmail.com wrote:
In Firefox ---- Goto Preferences ---> Choose Privacy and Security ---> scroll down until you get cookies and site data --> clear data
Chrome ---- Goto Settings ---> Choose Privacy and Security ---> select cookies and other site data --> select see all cookies and site data --> Remove all

On Sat, May 29, 2021 at 9:50 AM sukhy gill <sukhy.g...@gmail.com> wrote:
@Venu Gopal

No Sir, I don't know, how to do this.

May I know Sir, how to do the same?

Regards

On Sat, May 29, 2021, 09:41 Venu Gopal <reachme...@gmail.com wrote:
Hi, Have you tried deleting existing cache and cookies in the browser?

On Sat, May 29, 2021 at 12:08 AM sukhy gill <sukhy.g...@gmail.com> wrote:
Dear Frnds
                I am unable to  link CSS with HTML
HTML working but CSS not working inside the .html file with the help of LINK in <head> tag 

I am using thefollowings:-
Setting.py -  STATICFILES_DIRS=[os.path.join(BASE_DIR, 'static'),]
HTML- {% load static %}
<Link rel="stylesheet" href="{% static 'css/syle.css %} />
 
Regards

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3ca2aba0-a58f-4298-b248-16c51bdf90a6n%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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOhYkiyqw8k5zCL1XZo9U%2BY9_JR57p55xf-%3DtFf6Fa4HVskPSw%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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJ8btZave0utnYTAcrxafKes6sUZ3%2BX%2B0v1EGs-pJSF1%2BT4qxw%40mail.gmail.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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6270c1f5-a1d9-4904-a5ed-85e21030b894n%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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.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/qGMoFXNAgww/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3e26aaf1-212c-42fe-b7fe-b770dac85e4en%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJ8btZYb461qqot%2BMNRB4bNq4qcdAVWGni_uhfo1Yr6hzmJ0oA%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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJwZndcDCN5U7SAzYpuq%2BtPM0QCQz0XKw74jQsLvnPKXKUzLNw%40mail.gmail.com.