Moved HostingPlatform to separate folder

This commit is contained in:
Kristofers Solo 2023-04-09 13:30:01 +03:00
parent e0f2e615f3
commit 0b0d6539dc
6 changed files with 47 additions and 42 deletions

View File

@ -1,8 +1,9 @@
from django.contrib import admin
from .host.models import HostingPlatform, ProjectHostingPlatform
from .language.models import ProgrammingLanguage, ProjectProgrammingLanguage
from .license.models import License
from .models import HostingPlatform, Project, ProjectHostingPlatform, Tag
from .models import Project, Tag
class ProjectProgrammingLanguageInline(admin.TabularInline):

View File

@ -1,6 +1,6 @@
from django import forms
from .models import HostingPlatform, Project, ProjectHostingPlatform
from .models import Project
class ProjectForm(forms.ModelForm):
@ -20,20 +20,3 @@ class ProjectForm(forms.ModelForm):
}),
"licenses": forms.CheckboxSelectMultiple(),
}
class HostingPlatformForm(forms.ModelForm):
url = forms.URLField()
class Meta:
model = HostingPlatform
fields = ["hosting_platform", "url"]
ProjectHostingPlatformFormSet = forms.inlineformset_factory(
Project,
ProjectHostingPlatform,
form=HostingPlatformForm,
extra=1,
can_delete=False
)

View File

@ -0,0 +1,22 @@
from django import forms
from fossdb.models import Project
from .models import HostingPlatform, ProjectHostingPlatform
class HostingPlatformForm(forms.ModelForm):
url = forms.URLField()
class Meta:
model = HostingPlatform
fields = ["hosting_platform", "url"]
ProjectHostingPlatformFormSet = forms.inlineformset_factory(
Project,
ProjectHostingPlatform,
form=HostingPlatformForm,
extra=1,
can_delete=False
)

View File

@ -0,0 +1,17 @@
from django.db import models
class HostingPlatform(models.Model):
hosting_platform = models.CharField(max_length=100)
def __str__(self):
return self.hosting_platform
class ProjectHostingPlatform(models.Model):
project = models.ForeignKey("Project", on_delete=models.CASCADE)
hosting_platform = models.ForeignKey(HostingPlatform, on_delete=models.CASCADE)
url = models.URLField()
def __str__(self):
return f"{self.project} | {self.hosting_platform}"

View File

@ -3,19 +3,9 @@ import uuid
from django.conf import settings
from django.db import models
from .language.models import ProgrammingLanguage
from .license.models import License
User = settings.AUTH_USER_MODEL
class HostingPlatform(models.Model):
hosting_platform = models.CharField(max_length=100)
def __str__(self):
return self.hosting_platform
class Tag(models.Model):
name = models.CharField(max_length=100)
description = models.TextField(blank=True, default="")
@ -25,23 +15,14 @@ class Tag(models.Model):
return self.name
class ProjectHostingPlatform(models.Model):
project = models.ForeignKey("Project", on_delete=models.CASCADE)
hosting_platform = models.ForeignKey(HostingPlatform, on_delete=models.CASCADE)
url = models.URLField()
def __str__(self):
return f"{self.project} | {self.hosting_platform}"
class Project(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
author = models.ForeignKey(User, on_delete=models.CASCADE)
name = models.CharField(max_length=255)
description = models.TextField(blank=True, default="")
licenses = models.ManyToManyField(License)
programming_languages = models.ManyToManyField(ProgrammingLanguage, through="ProjectProgrammingLanguage", related_name="projects")
hosting_platform = models.ManyToManyField(HostingPlatform, through="ProjectHostingPlatform", related_name="projects")
licenses = models.ManyToManyField("License")
programming_languages = models.ManyToManyField("ProgrammingLanguage", through="ProjectProgrammingLanguage", related_name="projects")
hosting_platform = models.ManyToManyField("HostingPlatform", through="ProjectHostingPlatform", related_name="projects")
tag = models.ManyToManyField(Tag)
date_created = models.DateTimeField(auto_now_add=True)

View File

@ -1,7 +1,8 @@
from django.contrib.auth.decorators import login_required, permission_required
from django.shortcuts import redirect, render
from .forms import ProjectForm, ProjectHostingPlatformFormSet
from .forms import ProjectForm
from .host.forms import ProjectHostingPlatformFormSet
from .language.forms import ProjectProgrammingLanguageFormSet
from .models import Project