Created
May 17, 2018 23:38
-
-
Save djwesleyborges/9140248a199171a898047fab1125b878 to your computer and use it in GitHub Desktop.
Teste
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib.auth.models import User | |
from django.db import models | |
# Model cadastro de produto | |
class Advertisement(models.Model): | |
title = models.CharField(max_length=100) | |
address = models.CharField(max_length=100) | |
complement = models.CharField(max_length=100) | |
number = models.CharField(max_length=5) | |
zip_code = models.CharField(max_length=9) | |
value = models.CharField(max_length=8) | |
description = models.TextField() | |
image = models.ImageField(upload_to='media/%Y/%m/%d/', default='', verbose_name='Imagem') | |
created_at = models.DateTimeField('Created on: ', auto_now_add=True) | |
update_at = models.DateTimeField('Update on: ', auto_now=True) | |
created_by = models.ForeignKey(User, default=None, on_delete=models.CASCADE) | |
def __str__(self): | |
return self.title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from django.http import HttpResponse | |
from django.contrib.auth.decorators import login_required | |
from advertisement.forms import AdvertisementForm | |
from catalog.models import Product | |
from .models import Advertisement | |
# view cadastro de produto | |
def registerAdvertisement(request): | |
template_name = 'product/registration.html' | |
form = AdvertisementForm() | |
message = "Registered sucessfully!" | |
if request.method == "POST": | |
form = AdvertisementForm(request.POST, request.FILES) | |
if form.is_valid(): | |
form.save() | |
return HttpResponse( | |
'Registered sucessfully!' | |
'<br>' | |
'<a href="/home" class="btn btn-success"> Back</a>' | |
) | |
context = {'form': form} | |
return render(request, template_name, context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment