30 lines
977 B
Python
30 lines
977 B
Python
from django import forms
|
|
from .models import Sistema,sistemas_por_cliente
|
|
class SistemaForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Sistema
|
|
fields = ['nombre_sistema','version']
|
|
|
|
|
|
class sistemas_por_clienteForm(forms.ModelForm):
|
|
nombre_sistema = forms.CharField(max_length=100)
|
|
version = forms.CharField(max_length=25)
|
|
|
|
class Meta:
|
|
model = sistemas_por_cliente
|
|
fields = ['cliente', 'num_licencias']
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.fields['cliente'].empty_label = None
|
|
|
|
def save(self, commit=True):
|
|
sistema = Sistema.objects.create(
|
|
nombre_sistema=self.cleaned_data['nombre_sistema'],
|
|
version=self.cleaned_data['version'],
|
|
)
|
|
sistema_por_cliente = super().save(commit=False)
|
|
sistema_por_cliente.id_sistema = sistema
|
|
if commit:
|
|
sistema_por_cliente.save()
|
|
return sistema_por_cliente |