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 <javascript:> [mailto:
> django...@googlegroups.com <javascript:>] *On Behalf Of *cale...@gmail.com 
> <javascript:>
> *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 <javascript:>.
> To post to this group, send email to djang...@googlegroups.com 
> <javascript:>.
> 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&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

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

Reply via email to