Writing - pai-plznw4me/django-initializer GitHub Wiki
WEB κ°λ° νμ€
-
Django DateField
-
Form λ΄ Meta class μ μλ widget μΆκ°
-
widgets = { '{{fieldname}}': forms.widgets.DateInput(attrs={'type': 'date'}) }
-
# λ¬Έμ μ λ‘λ μκ° # νμΌ μ λ‘λμ μλμ κ°μ νλ μΆκ° upload_date = models.DateField(auto_now_add=True)
-
Django ImageField
-
Django Graph
-
Django table
- https://datatables.net/ μ νμ¬ νμ€ table λ‘ μ§μ νλ€.
-
Django BI
-
File management system
- νμΌμ μ¬λ¬κ° λ§λ€μ΄μΌ νλ€κ³ νμ μ΄λ»κ² κ΄λ¦¬ ν κ²μΈκ°?
- νμΌ κ΄λ¦¬ DBμ λ§λ€μ΄μ κ΄λ¦¬ν΄μΌ νλ€.
-
CharField
-
choice
-
ν¬λ§· κ°μ νκΈ°
from django.db import models from django.core.exceptions import ValidationError from django.core.validators import RegexValidator def validate_version_format(value): version_regex = r'^v\d+\.\d+\.\d+$' if not re.match(version_regex, value): raise ValidationError('Invalid version format. Use the format "vX.X.X".') class YourModel(models.Model): version = models.CharField(max_length=10, validators=[validate_version_format]) # λ€λ₯Έ νλλ€...
-
-
pms μ λ§λ λ€κ³ νμ
- λλ κ°λ°ν λ μ¬λ¬ λΉμ νμ μ 보λ€μ μ§μμ μΌλ‘ μΆκ°ν΄μΌ νλ€.
- pms db μμ λ£μλ €κ³ νμ§λ§ κ²°κ΅ file db μ λ°λ‘ λ§λ€μλ€.
-
μ½λ μ체λ₯Ό λ³κ²½ νλ λ°©λ²
-
shell
-
ast
import ast file_path = "a.py" app_name = "helloworld" # νμΌ μ½κΈ° with open(file_path, "r") as file: code = file.read() # μ½λ νμ± tree = ast.parse(code) # INSTALLED_APPSλ₯Ό μ°Ύμμ λ Έλμ 'helloworld' μΆκ° for node in ast.walk(tree): if isinstance(node, ast.Assign): for target in node.targets: if isinstance(target, ast.Name) and target.id == 'INSTALLED_APPS': if isinstance(node.value, ast.List): node.value.elts.append(ast.Str(s=app_name)) # μμ λ μ½λ μμ± modified_code = compile(tree, filename=file_path, mode='exec') # νμΌμ μμ λ μ½λ μ μ₯ with open(file_path, "w") as file: file.write(modified_code) print(f"App '{app_name}' added to INSTALLED_APPS in {file_path}.")
-
-
Model - form - view - template κ°λ°
-
Model
from django.db import models # Create your models here. class File(models.Model): # νμΌ μ΄λ¦ name = models.CharField(max_length=100) # λ¬Έμ μ λ‘λ μκ° upload_date = models.DateField() # λ¬Έμ μμ± μκ° creation_date = models.DateField() # λ¬Έμ λ²μ name = models.CharField(max_length=100) # Project PROJECT_CHOICES = [ ('A', 'AAA'), ('B', 'BBB'), ('C', 'CCC'), ] project = models.CharField(max_length=10, choices=PROJECT_CHOICES) # file content filecontent = models.FileField() # image content imagecontent= models.ImageField()
-
Form
class CreateFileForm(forms.ModelForm): class Meta: model = File fields = ['name', 'upload_date', 'creation_date', 'name', 'project', 'filecontent', 'imagecontent']
-
View
-
Templates
<!-- templates/registration/login.html --> <h2>Signup</h2> <form action="" method="post" enctype="multipart/form-data"> {% csrf_token %} {{ form.as_p }} <button type="submit">Signup</button> </form> {{ errors }}
-
- FileCreationForm {λͺ¨λΈλͺ }{λͺ©μ λͺ }Form