Wednesday, January 30, 2019

Re: NoReverseMatch at /someurlname/ - Reverse for 'htmlname' with arguments '('1',)' not found. 1 pattern(s) tried: ['somehtmlname/$']

app 1
view:
from django.shortcuts import render, redirect
from django.http import HttpResponse
from .models import AbcClassification
from django.db import connection
from .forms import AbcForm
from django.core.mail import send_mail
from django.conf import settings
from django.core.mail import send_mail
from django.contrib import messages
import time
from django.contrib.auth import login, logout
from django.contrib.auth.decorators import user_passes_test, login_required

def check_user(user):
if user.groups.filter(name='abc_all').count() == 1:
return True
return False

@login_required(login_url='/accounts/login/')
@user_passes_test(check_user, login_url='/denied')

def abc_view(request):
queryset = AbcClassification.objects.all()
context = {
"lista" : queryset,
}
return render(request, "qif/abc.html", context)

@login_required(login_url='/accounts/login/')
@user_passes_test(check_user, login_url='/denied')

def abc_update_view(request, url_id):
abc_lista = AbcClassification.objects.get(id=url_id)
abc_url_id = AbcForm(request.POST or None, instance=abc_lista)
context1 = {'abc_url_id': abc_url_id, 'abc_lista': abc_lista}

if abc_url_id.is_valid():
abc_url_id.save()
messages.success(request, 'Your entry has been saved. Relevant persons will be informed of this change.')
return render(request, 'qif/abc-update.html', context1)

url:
from django.urls import path
from . import views


urlpatterns = [
path('', views.abc_view, name='abc'),
path('update/<int:url_id>/', views.abc_update_view, name='update_abc'),
]


model:
from __future__ import unicode_literals
from django.db import models, connection
from django.utils import timezone
from simple_history.models import HistoricalRecords
from django.contrib.auth.models import User




class AbcClassification(models.Model):
id = models.IntegerField(db_column='ID', primary_key=True)
class_field = models.CharField(db_column='Class', max_length=1)
value = models.SmallIntegerField(db_column='Value')

history = HistoricalRecords()


class Meta:
managed = False
db_table = 'ABC_Classification'

def __str__(self):
return '%s %s' % (self.class_field, self.value, self.id)


app2

view:
from django.shortcuts import render, redirect
from django.http import HttpResponse
from .models import Material4, MaterialGroup
from django.db import connection
from .forms import ProductgroupinputForm, MaterialGroupForm
from django.core.mail import send_mail
from django.conf import settings
from django.core.mail import send_mail
from django.contrib import messages
from django.db.models import Q
from django.contrib.auth import login, logout
from django.contrib.auth.decorators import user_passes_test, login_required
from django.shortcuts import get_object_or_404

def check_user(user):
if user.groups.filter(name='productsgrouping_all').count() == 1:
return True
return False


#novi views
@login_required(login_url='/accounts/login/')
@user_passes_test(check_user, login_url='/denied')

def productsgrouping_view(request):
queryset = MaterialGroup.objects.all()
#not_assigned = Material4.objects.filter(input_group__isnull=True).count()
context = {
"lista" : queryset,
#"not_assigned":not_assigned
}

return render(request, 'qif/productsgrouping/productsgroup.html', context)

@login_required(login_url='/accounts/login/')
@user_passes_test(check_user, login_url='/denied')

def productsgrouping_update_view(request, url_id):
#assigned = get_object_or_404(id=url_id)
assigned = Material4.objects.filter(input_group=url_id)
not_assigned = None
search = request.GET.get("search", None)

if search:
not_assigned = Material4.objects.filter(Q(materialid__icontains=search) | Q(maktx__icontains=search))


product_lista = MaterialGroup.objects.get(id=url_id)
#product_lista = get_object_or_404(MaterialGroup, pk=url_id)
product_url_id = ProductgroupinputForm(request.POST or None, instance=product_lista)
context1 = {
'product_url_id': product_url_id,
'product_lista': product_lista,
'assigned':assigned,
'not_assigned':not_assigned,
'search': search,
}

if product_url_id.is_valid():
product_url_id.save()
messages.success(request, 'Your entry has been saved. Relevant persons will be informed of this change.')
#time.sleep(5)

return render(request, 'qif/productsgrouping/productsgroup-update.html', context1)

@login_required(login_url='/accounts/login/')
@user_passes_test(check_user, login_url='/denied')

def creategroup_view(request):
forma = MaterialGroupForm(request.POST or None)

return render(request, 'qif/productsgrouping/productsgroup-create.html', {'forma':forma})

url:
from django.urls import path
from . import views


urlpatterns = [
path('', views.productsgrouping_view, name='productsgrouping'),
path('update/<int:url_id>/', views.productsgrouping_update_view, name='update_productsgrouping'),
path('new/', views.creategroup_view, name='create_group'),
]

model:
from __future__ import unicode_literals
from django.db import models, connection
from django.utils import timezone
from datetime import date
from simple_history.models import HistoricalRecords



class Material4(models.Model):
id = models.IntegerField(db_column='ID', primary_key=True, blank=False, unique=True)
bukrs = models.CharField(db_column='BUKRS', max_length=3)
materialid = models.CharField(db_column='MaterialID', max_length=50)
maktx = models.CharField(db_column='MAKTX', max_length=150)
input_group = models.IntegerField(db_column='Input_group')
#input_group = models.IntegerField(db_column='Input_group', blank=True, null=True)

history = HistoricalRecords()

class Meta:
managed = False
db_table = 'Material4'

def __str__(self):
return '%s %s' % (self.materialid, self.maktx)


class MaterialGroup(models.Model):
id = models.CharField(db_column='ID', max_length=255, blank=False, primary_key=True)
material_group = models.CharField(db_column='Material Group', max_length=255, blank=True, null=True)

class Meta:
managed = False
db_table = 'Material Group'

def __str__(self):
return '%s' % (self.material_group)




Bok Nebojša, jel možeš uletit i pogledati molim te što radim krivo.

Znači, imam 2 aplikacije, prva abc radi a druga product groups ne radi..
Sve je kopirano u 2 privitka.

Da li imaš vremena pogledati pliz?
Šta god napravim, No reverse mi se javlja....... 

--
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/CAFab_C8%2BhPxKUsLah%3D%3DtOrn8ro8-DgA3GFhy8%2Bz99kF4r80tog%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment