Olá! Não consigo realizar o makemigrations e não encontro o erro...
erro
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 354, in execute
django.setup()
File "C:\Python27\lib\site-packages\django\__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 108, in populate
app_config.import_models(all_models)
File "C:\Python27\lib\site-packages\django\apps\config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\jojih\Desktop\connectedin\perfis\models.py", line 14, in <module>
class Convite(models.Model):
File "C:\Users\jojih\Desktop\connectedin\perfis\models.py", line 20, in Convite
self.solicitante.contatos.add(self.convidado)
NameError: name 'self' is not defined
urls.py:
from django.conf.urls import patterns, url
from django.contrib import admin
from perfis import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index'),
url(r'^perfis/(?P<perfil_id>\d+)$', views.exibir, name='exibir'),
url(r'^perfis/(?P<perfil_id>\d+)/convidar$', views.convidar, name='convidar'),
url(r'^convite/(?P<convite_id>\d+)/aceitar$', views.aceitar, name='aceitar')
)
views.py:
from django.shortcuts import render, redirect
from django.http import HttpResponse
from perfis.models import Perfil, Convite
def index(request):
return render(request, 'index.html',{ 'perfis' : Perfil.objects.all(), 'perfil_logado' : get_perfil_logado(request)})
def exibir(request, perfil_id):
perfil = Perfil.objects.get(id=perfil_id)
return render(request, 'perfil.html', {'perfil' : perfil, 'perfil_logado' : get_perfil_logado(request)})
def convidar(request, perfil_id):
perfil_a_convidar = Perfil.objects.get(id= perfil_id)
perfil_logado = get_perfil_logado(request)
perfil_logado.convidar(perfil_a_convidar)
return redirect ('index')
def aceitar(request, convite_id):
convite = Convite.objects.get(id=convite_id)
convite.aceitar()
return redirect('index')
def get_perfil_logado(request):
return Perfil.objects.get(id=1)
models.py:
from django.db import models
class Perfil(models.Model):
nome = models.CharField(max_length=255, null=False)
email = models.CharField(max_length=255, null=False)
telefone = models.CharField(max_length=100, null=False)
nome_empresa = models.CharField(max_length=255, null=False)
contatos = models.ManyToManyField('self')
def convidar(self, perfil_convidado):
Convite(solicitante=self, convidado=pefil_convidado).save()
class Convite(models.Model):
solicitante = models.ForeignKey(Perfil, related_name='convites_feitos')
convidado = models.ForeignKey(Perfil, related_name='convites_recebidos')
def aceitar(self):
self.convidado.contatos.add(self.solicitante)
self.solicitante.contatos.add(self.convidado)
self.delete()
index.html:
{% extends "base.html" %}
{% block body %}
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<strong>Todos os Perfis</strong>
</div>
{% if perfis %}
<ul>
{% for perfil in perfis %}
<li>
<a href="{% url 'exibir' perfil.id %}">{{ perfil.nome }}</a> / {{ perfil.email }}
</li>
{% endfor %}
</ul>
{% else %}
<p>Nenhum Perfil encontrado</p>
{% endif %}
</div>