Currently moving from Gitlab to Gitea at Some features may not work anymore on this Gitlab instance.

better models

parent 6a7b5093
Models for the database of the dictionary. This dictionary is thought of as a
bilingual dictionary capable of translating back and forth between natlangs
and the conlangs of
from django.db import models
from django.utils import slugify
class Languages(models.Model):
code = models.CharField(max_length=3, primary_key=True)
name = models.CharField(max_length=100)
class Language(models.Model):
"""A general class to refer to languages, with its code and its name"""
code = models.CharField(max_length=4, primary_key=True)
name = models.CharField(max_length=128)
def __str__(self):
return + " (" + self.code + ")"
return "{} ({0.code})".format(self)
class Meta:
"""Meta sub-class for ordering the languages"""
ordering = ('code', )
class Genders(models.Model):
class Gender(models.Model):
"""Contains all possible gender in the languages supported by the
dictionary, be it from natlangs or conlangs"""
code = models.CharField(max_length=4, primary_key=True)
name = models.CharField(max_length=100)
name = models.CharField(max_length=128)
def __str__(self):
return "{} ({0.code})".format(self)
class Meta:
"""Meta sub-class for ordering the genders"""
ordering = ('name', )
class Wordclasses(models.Model):
class Wordclass(models.Model):
"""Contains all the word classes available in the supported languages"""
code = models.CharField(max_length=4, primary_key=True)
name = models.CharField(max_length=50)
name = models.CharField(max_length=64)
def __str__(self):
return "{} ({0.code})".format(self)
class Meta:
"""Meta sub-class for ordering the word classes"""
ordering = ('code', )
class Words(models.Model):
word = models.CharField(max_length=100)
language = models.ForeignKey(Languages, on_delete=models.CASCADE)
translation = models.ManyToManyField("self")
gender = models.ForeignKey(Genders, on_delete=models.SET_NULL)
type = models.ForeignKey(Wordclasses, on_delete=models.SET_NULL)
details = models.CharField(max_length=5000, blank=True)
etymology = models.CharField(max_length=5000, blank=True)
roots = models.ManyToManyField("self", on_delete=models.SET_NULL, blank=True)
class Word(models.Model):
"""Represents any word from any language. It has a self-representation with
\"word\", a reference to which language it belongs to with \"language\",
a list of words \"translation\" that can be its translation (duh), a
reference to its gender with \"gender\" (duh2), its word class with
\"wordclass\", some \"details\" about the word (no more than 5000 chars),
its \"etymology\" (no more than 5000 chars) and a list of words that can be
its etymological \"roots\"
word = models.CharField(max_length=124)
slug = models.CharField(max_length=124)
language = models.ForeignKey(Language, on_delete=models.CASCADE)
translation = models.ManyToManyField("self", blank=True)
gender = models.ForeignKey(Gender, on_delete=models.SET_NULL)
wordclass = models.ForeignKey(Wordclass, on_delete=models.SET_NULL)
details = models.CharField(max_length=8192, blank=True)
etymology = models.CharField(max_length=8192, blank=True)
roots = models.ManyToManyField(
"self", on_delete=models.SET_NULL, blank=True)
def __str__(self):
return self.word
def save(self, *args, **kwargs):
if self.word:
self.slug = slugify(self.word)
super(Word, self).save(args, kwargs)
class Meta:
ordering = ('word', )
from django.conf.urls import url
from . import views
app_name = 'dict'
urlpatterns = [
# /dict/lang=HJA/tay => renvoie cinq mots commençant par `tay`
url(r'^lang=<language>[a-zA-Z]+\?\w/*$', views.guess, name='guess'),
# /dict/from=FRA/to=HJA/jour => renvoie le sommaire de la traduction de
# `jour`
# /dict/lang=HJA/details=bém
......@@ -15,7 +15,9 @@ Including another URLconf
from django.contrib import admin
from django.urls import path
from django.conf.urls import include
urlpatterns = [
path('dictionary', include('dict.urls')),
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment