Move type field to signal

This commit is contained in:
Mark Veidemanis 2022-12-07 07:20:11 +00:00
parent 2ee5f7b937
commit e388624f65
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
3 changed files with 30 additions and 7 deletions

View File

@ -72,12 +72,10 @@ class HookForm(RestrictedFormMixin, ModelForm):
fields = ( fields = (
"name", "name",
"hook", "hook",
"type",
) )
help_texts = { help_texts = {
"name": "Name of the hook. Informational only.", "name": "Name of the hook. Informational only.",
"hook": "The URL slug to use for the hook. Make it unique.", "hook": "The URL slug to use for the hook. Make it unique.",
"type": "Whether the hook is used for entering or exiting trades, or determining the trend.",
} }
@ -88,12 +86,14 @@ class SignalForm(RestrictedFormMixin, ModelForm):
"name", "name",
"signal", "signal",
"hook", "hook",
"type",
"direction", "direction",
) )
help_texts = { help_texts = {
"name": "Name of the signal. Informational only.", "name": "Name of the signal. Informational only.",
"signal": "The name of the signal in Drakdoo. Copy it from there.", "signal": "The name of the signal in Drakdoo. Copy it from there.",
"hook": "The hook this signal belongs to.", "hook": "The hook this signal belongs to.",
"type": "Whether the signal is used for entering or exiting trades, or determining the trend.",
"direction": "The direction of the signal. This is used to determine if the signal is a buy or sell.", "direction": "The direction of the signal. This is used to determine if the signal is a buy or sell.",
} }
@ -119,9 +119,9 @@ class AccountForm(RestrictedFormMixin, ModelForm):
class StrategyForm(RestrictedFormMixin, ModelForm): class StrategyForm(RestrictedFormMixin, ModelForm):
fieldargs = { fieldargs = {
"entry_signals": {"hook__type": "entry"}, "entry_signals": {"type": "entry"},
"exit_signals": {"hook__type": "exit"}, "exit_signals": {"type": "exit"},
"trend_signals": {"hook__type": "trend"}, "trend_signals": {"type": "trend"},
} }
class Meta: class Meta:

View File

@ -0,0 +1,23 @@
# Generated by Django 4.1.3 on 2022-12-07 10:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0045_hook_type'),
]
operations = [
migrations.RemoveField(
model_name='hook',
name='type',
),
migrations.AddField(
model_name='signal',
name='type',
field=models.CharField(choices=[('entry', 'Entry'), ('exit', 'Exit'), ('trend', 'Trend')], default='entry', max_length=255),
preserve_default=False,
),
]

View File

@ -35,7 +35,7 @@ DAY_CHOICES = (
(6, "Saturday"), (6, "Saturday"),
(7, "Sunday"), (7, "Sunday"),
) )
HOOK_TYPE_CHOICES = ( SIGNAL_TYPE_CHOICES = (
("entry", "Entry"), ("entry", "Entry"),
("exit", "Exit"), ("exit", "Exit"),
("trend", "Trend"), ("trend", "Trend"),
@ -174,7 +174,6 @@ class Hook(models.Model):
name = models.CharField(max_length=1024) name = models.CharField(max_length=1024)
hook = models.CharField(max_length=255, unique=True) # hook URL hook = models.CharField(max_length=255, unique=True) # hook URL
received = models.IntegerField(default=0) received = models.IntegerField(default=0)
type = models.CharField(choices=HOOK_TYPE_CHOICES, max_length=255)
def __str__(self): def __str__(self):
return f"{self.name} ({self.hook})" return f"{self.name} ({self.hook})"
@ -187,6 +186,7 @@ class Signal(models.Model):
hook = models.ForeignKey(Hook, on_delete=models.CASCADE) hook = models.ForeignKey(Hook, on_delete=models.CASCADE)
direction = models.CharField(choices=DIRECTION_CHOICES, max_length=255) direction = models.CharField(choices=DIRECTION_CHOICES, max_length=255)
received = models.IntegerField(default=0) received = models.IntegerField(default=0)
type = models.CharField(choices=SIGNAL_TYPE_CHOICES, max_length=255)
def __str__(self): def __str__(self):
return f"{self.name} ({self.hook.name}) - {self.direction}" return f"{self.name} ({self.hook.name}) - {self.direction}"