Wednesday, May 30, 2018

Re: Django Model

Hi,

If I got this right, what you want to do is save the "domainwhois" with the expiration date of the result of the whois.whois function.

Unfortunately, things don't work in class level like this, because things are static here: whois.whois will be run one single time, not on every object. For that, you'll need to change something in the instance. Fortunately, Django allows access to things in the instance with ``save``:

def save(self, *args, **kwargs):
   details = whois.whois(self.domainname)
   self.domainwhois = details.expiration_date
   super().save(*args, **kwargs)

("details" and "w" can be removed from the model itself, as they are variables used only for retriving this information). Have a look how models work here: https://docs.djangoproject.com/en/2.0/topics/db/models/

On Wed, May 30, 2018 at 11:12 AM, Максим С <seosgcert@gmail.com> wrote:
Hello all.

I'm beginer. Sorry. Can anyone help me with this model. It did't work(TypeError: expected string or bytes-like object

):

import whois

class Domains(models.Model):
domainname = models.CharField(max_length=200, blank=True)
domainuser = models.ForeignKey(User, on_delete=models.CASCADE)
details = whois.whois(domainname)
w = str(details.expiration_date)
domainwhois = models.DateField(default=w)

def __str__(self):
return self.domainname

Domains.save()

--
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 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/53525a55-0d68-4a8c-9031-5d7c3baa7064%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Julio Biason, Sofware Engineer
AZION  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101  |  Mobile: +55 51 99907 0554

--
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 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/CAEM7gE2N1hVwL-W0z%2BssYsvmmBrnnJxOUT_ZaV7NxY_jH8V%2BNg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment