Re: Overriding Save in Model

2019-01-16 Thread caleoroco
Thanks, I did say i was only two weeks into learning python and Django.

I'm sure in a few months, maybe weeks or even days, i'll look back at my 
code and say wtf


On Wednesday, 16 January 2019 17:21:24 UTC, Matthew Pava wrote:
>
> You’re converting an object (ExtractResult) into a list.  That’s just 
> weird.
>
>  
>
> ext = tldextract.extract(domain)
>
> self.sub_domain = ext.subdomain
>
> self.domain = ext.domain
>
> self.suffix = ext.suffix
>
>  
>
> Saying that, I would rather use the built-in, Pythonic way of parsing URLs.
>
>  
>
> *From:* django...@googlegroups.com  [mailto:
> django...@googlegroups.com ] *On Behalf Of *cale...@gmail.com 
> 
> *Sent:* Wednesday, January 16, 2019 11:07 AM
> *To:* Django users
> *Subject:* Re: Overriding Save in Model
>
>  
>
> thanks,  i've got tldextract which is sufficient for splitting the domain 
> up
>
>  
>
> the problem is I cannot save the individual parts and only end up saving 
> the domain name
>
> On Wednesday, 16 January 2019 16:55:42 UTC, Matthew Pava wrote:
>
> Check out urllib.parse.
>
> https://docs.python.org/3/library/urllib.parse.html
>
>  
>
>  
>
> *From:* django...@googlegroups.com [mailto:django...@googlegroups.com] *On 
> Behalf Of *cale...@gmail.com
> *Sent:* Wednesday, January 16, 2019 10:41 AM
> *To:* Django users
> *Subject:* Overriding Save in Model
>
>  
>
> I'm trying to extract an entered domain name and split it up so that i can 
> store unique domains in a specific table
>
> The flow
>
> user will enter website address > model takes website address > splits it 
> into sub_domain, domain and suffix and stores the values in the appropriate 
> split fields
>
>  
>
> so far my extraction works, i can get the values into a list and assign 
> the values to the appropriate variables, using the shell i'm adding new 
> sites but and the domain is going into the domain_name field but i am not 
> getting the data split
>
>  
>
> I'm only two weeks into learning python and Django and i love it but this 
> has stopped me in my tracks for now, any help appreciated
>
>  
>
> *class *Website(models.Model):
> name = models.CharField(max_length=100, default=' ')
> description = models.TextField(max_length=2000, blank=*True*)
> domain_name = models.URLField(unique=*True*)
> sub_domain =models.CharField(max_length=56, blank=*True*, default='')
> suffix = models.CharField(max_length=56, blank=*True*, default='')
> is_secure = models.BooleanField(null=*True*)
> logo = models.CharField(max_length=256, default="placeholder.png")
> type = models.CharField(choices=WEBSITE_TYPES, default='O', max_length=15)
>
> *def __str__*(self):
> *return *self.name
>
>
> *def *validate_and_split_domain(self):
> domain = self.domain_name.lower() # make all lower case because 
> django isn't case sensitive
> values = list(tldextract.extract(domain))
> self.sub_domain, self.domain_name, self.suffix = values[0], 
> values[1], values[2]
>
> *def *save(self, **args*, ***kwargs*):
> Website.validate_and_split_domain()
> super(Website, self).save(**args*, ***kwargs*)
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com.
> To post to this group, send email to djang...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/94d5ffbb-8975-471a-b9bb-30870e893ee8%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/94d5ffbb-8975-471a-b9bb-30870e893ee8%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to djang...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/b15fe16b-4eef-4514-a51c-5442a9aca028%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/b15fe16b-4eef-4514-a51c-5442a9aca028%40googlegroups.com?utm_medium=email_source=footer>
>

RE: Overriding Save in Model

2019-01-16 Thread Matthew Pava
You’re converting an object (ExtractResult) into a list.  That’s just weird.

ext = tldextract.extract(domain)
self.sub_domain = ext.subdomain
self.domain = ext.domain
self.suffix = ext.suffix

Saying that, I would rather use the built-in, Pythonic way of parsing URLs.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of caleor...@gmail.com
Sent: Wednesday, January 16, 2019 11:07 AM
To: Django users
Subject: Re: Overriding Save in Model

thanks,  i've got tldextract which is sufficient for splitting the domain up

the problem is I cannot save the individual parts and only end up saving the 
domain name

On Wednesday, 16 January 2019 16:55:42 UTC, Matthew Pava wrote:
Check out urllib.parse.
https://docs.python.org/3/library/urllib.parse.html


From: django...@googlegroups.com 
[mailto:django...@googlegroups.com] On Behalf Of 
cale...@gmail.com
Sent: Wednesday, January 16, 2019 10:41 AM
To: Django users
Subject: Overriding Save in Model

I'm trying to extract an entered domain name and split it up so that i can 
store unique domains in a specific table
The flow
user will enter website address > model takes website address > splits it into 
sub_domain, domain and suffix and stores the values in the appropriate split 
fields

so far my extraction works, i can get the values into a list and assign the 
values to the appropriate variables, using the shell i'm adding new sites but 
and the domain is going into the domain_name field but i am not getting the 
data split

I'm only two weeks into learning python and Django and i love it but this has 
stopped me in my tracks for now, any help appreciated


class Website(models.Model):
name = models.CharField(max_length=100, default=' ')
description = models.TextField(max_length=2000, blank=True)
domain_name = models.URLField(unique=True)
sub_domain =models.CharField(max_length=56, blank=True, default='')
suffix = models.CharField(max_length=56, blank=True, default='')
is_secure = models.BooleanField(null=True)
logo = models.CharField(max_length=256, default="placeholder.png")
type = models.CharField(choices=WEBSITE_TYPES, default='O', max_length=15)

def __str__(self):
return self.name


def validate_and_split_domain(self):
domain = self.domain_name.lower() # make all lower case because django 
isn't case sensitive
values = list(tldextract.extract(domain))
self.sub_domain, self.domain_name, self.suffix = values[0], values[1], 
values[2]

def save(self, *args, **kwargs):
Website.validate_and_split_domain()
super(Website, self).save(*args, **kwargs)
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users...@googlegroups.com.
To post to this group, send email to djang...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/94d5ffbb-8975-471a-b9bb-30870e893ee8%40googlegroups.com<https://groups.google.com/d/msgid/django-users/94d5ffbb-8975-471a-b9bb-30870e893ee8%40googlegroups.com?utm_medium=email_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b15fe16b-4eef-4514-a51c-5442a9aca028%40googlegroups.com<https://groups.google.com/d/msgid/django-users/b15fe16b-4eef-4514-a51c-5442a9aca028%40googlegroups.com?utm_medium=email_source=footer>.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2c1b91dafe534b1e8ec07b90b4ec92bf%40iss2.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Re: Overriding Save in Model

2019-01-16 Thread caleoroco
thanks,  i've got tldextract which is sufficient for splitting the domain up

the problem is I cannot save the individual parts and only end up saving 
the domain name

On Wednesday, 16 January 2019 16:55:42 UTC, Matthew Pava wrote:
>
> Check out urllib.parse.
>
> https://docs.python.org/3/library/urllib.parse.html
>
>  
>
>  
>
> *From:* django...@googlegroups.com  [mailto:
> django...@googlegroups.com ] *On Behalf Of *cale...@gmail.com 
> 
> *Sent:* Wednesday, January 16, 2019 10:41 AM
> *To:* Django users
> *Subject:* Overriding Save in Model
>
>  
>
> I'm trying to extract an entered domain name and split it up so that i can 
> store unique domains in a specific table
>
> The flow
>
> user will enter website address > model takes website address > splits it 
> into sub_domain, domain and suffix and stores the values in the appropriate 
> split fields
>
>  
>
> so far my extraction works, i can get the values into a list and assign 
> the values to the appropriate variables, using the shell i'm adding new 
> sites but and the domain is going into the domain_name field but i am not 
> getting the data split
>
>  
>
> I'm only two weeks into learning python and Django and i love it but this 
> has stopped me in my tracks for now, any help appreciated
>
>  
>
> *class *Website(models.Model):
> name = models.CharField(max_length=100, default=' ')
> description = models.TextField(max_length=2000, blank=*True*)
> domain_name = models.URLField(unique=*True*)
> sub_domain =models.CharField(max_length=56, blank=*True*, default='')
> suffix = models.CharField(max_length=56, blank=*True*, default='')
> is_secure = models.BooleanField(null=*True*)
> logo = models.CharField(max_length=256, default="placeholder.png")
> type = models.CharField(choices=WEBSITE_TYPES, default='O', max_length=15)
>
> *def __str__*(self):
> *return *self.name
>
>
> *def *validate_and_split_domain(self):
> domain = self.domain_name.lower() # make all lower case because 
> django isn't case sensitive
> values = list(tldextract.extract(domain))
> self.sub_domain, self.domain_name, self.suffix = values[0], 
> values[1], values[2]
>
> *def *save(self, **args*, ***kwargs*):
> Website.validate_and_split_domain()
> super(Website, self).save(**args*, ***kwargs*)
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to djang...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/94d5ffbb-8975-471a-b9bb-30870e893ee8%40googlegroups.com
>  
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b15fe16b-4eef-4514-a51c-5442a9aca028%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: Overriding Save in Model

2019-01-16 Thread Matthew Pava
Check out urllib.parse.
https://docs.python.org/3/library/urllib.parse.html


From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of caleor...@gmail.com
Sent: Wednesday, January 16, 2019 10:41 AM
To: Django users
Subject: Overriding Save in Model

I'm trying to extract an entered domain name and split it up so that i can 
store unique domains in a specific table
The flow
user will enter website address > model takes website address > splits it into 
sub_domain, domain and suffix and stores the values in the appropriate split 
fields

so far my extraction works, i can get the values into a list and assign the 
values to the appropriate variables, using the shell i'm adding new sites but 
and the domain is going into the domain_name field but i am not getting the 
data split

I'm only two weeks into learning python and Django and i love it but this has 
stopped me in my tracks for now, any help appreciated


class Website(models.Model):
name = models.CharField(max_length=100, default=' ')
description = models.TextField(max_length=2000, blank=True)
domain_name = models.URLField(unique=True)
sub_domain =models.CharField(max_length=56, blank=True, default='')
suffix = models.CharField(max_length=56, blank=True, default='')
is_secure = models.BooleanField(null=True)
logo = models.CharField(max_length=256, default="placeholder.png")
type = models.CharField(choices=WEBSITE_TYPES, default='O', max_length=15)

def __str__(self):
return self.name


def validate_and_split_domain(self):
domain = self.domain_name.lower() # make all lower case because django 
isn't case sensitive
values = list(tldextract.extract(domain))
self.sub_domain, self.domain_name, self.suffix = values[0], values[1], 
values[2]

def save(self, *args, **kwargs):
Website.validate_and_split_domain()
super(Website, self).save(*args, **kwargs)
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
django-users+unsubscr...@googlegroups.com.
To post to this group, send email to 
django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/94d5ffbb-8975-471a-b9bb-30870e893ee8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9847dabf01254e1191742f46df6a088a%40iss2.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.