how to update image in django 1

how to update image in django

from __future__ import unicode_literals

from django.db import models
from django.core.urlresolvers import reverse

class Server(models.Model):
    name = models.CharField(max_length=200)
ip = models.GenericIPAddressField()
order = models.IntegerField()
image = models.FileField(upload_to='pics/',default='download.jpg') 

def __unicode__(self):
    return self.name

def get_absolute_url(self):
    return reverse('server_edit', kwargs={'pk': self.pk})

Here is what the above code is Doing:
1. We import the models module from Django.
2. We create a class called Server, which inherits from models.Model.
3. We define the name, ip, and order fields.
4. We define the __unicode__() method, which tells Django how to print objects of this type.
5. We define the get_absolute_url() method, which tells Django how to calculate the canonical URL for an object.

Similar Posts