Django model form pre-populating fields with my NT Login value

13 views
Skip to first unread message

Robert Prince

unread,
May 11, 2016, 7:23:58 PM5/11/16
to Django users
My first experience using django, python and bootstrap to build an application - I am struggling a bit.

The application is in development and does not have a login screen yet.

My issue in this instance, I have a model form which creates and updates eight field values to define and store database connections.

For some odd reason, my NT Login value is pre-populating one of the fields (db_user) when creating a new record.  I have not idea where django is picking up my NT Login value and why it is placing it in the "db_user" form column.

I can set the db_user default= ' ' to the column being populated with my NT, and this fixes the issue, but it causes the "placeholder" value to disappear.

Any idea why my NT Login is showing up one of the form's fields?

class connection_ref(models.Model):
    connection_id = models.IntegerField(primary_key=True)
    connection_type = models.CharField(max_length=50, default='DB', editable=False)
    connection_name = models.CharField(unique=True, max_length=256)
    db_type = models.CharField(max_length=50, choices=TYPE_CHOICES)
    db_nm = models.CharField(max_length=50)
    db_host_nm = models.CharField(max_length=256)
    db_port = models.CharField(max_length=10)
    db_schema = models.CharField(max_length=50)
    db_user = models.CharField(max_length=50)
    db_password = models.CharField(max_length=256)
    audit_updated_ts = models.DateTimeField(auto_now=True, auto_now_add=False)
    audit_inserted_ts = models.DateTimeField(auto_now=False, auto_now_add=True)
    class Meta:
        managed = False
        db_table = "connection_ref"

    def __str__(self):
        return self.connection_name

    def get_absolute_url(self):
        return reverse("admin_db_conn:update", kwargs={"connection_id": self.connection_id})


class AdminDBConnForm(forms.ModelForm):
    class Meta:
        model = connection_ref
        fields = [
            "db_type",
            "connection_name",
            "db_nm",
            "db_host_nm",
            "db_port",
            "db_schema",
            "db_user",
            "db_password"
        ]
        widgets = { 'db_type': forms.Select(attrs={'class': "form-control", "onChange":'hideShowDBFields(this.value)'}),
                    'connection_name': forms.TextInput(attrs={'class': "form-control", 'placeholder':"Enter the database connection name"}),
                    'db_nm': forms.TextInput(attrs={'class': "form-control", 'placeholder':"Enter the database name"}),
                    'db_host_nm': forms.TextInput(attrs={'class': "form-control", 'placeholder':"Enter the host"}),
                    'db_port': forms.TextInput(attrs={'class': "form-control", 'placeholder':"Enter the port"}),
                    'db_schema': forms.TextInput(attrs={'class': "form-control", 'placeholder':"Enter the schema name"}),
                    'db_user': forms.TextInput(attrs={'class': "form-control", 'placeholder':"Enter the database username"}),
                    'db_password': forms.PasswordInput(attrs={'class': "form-control", 'placeholder':"Enter the database password"})
        }

This is also happening in another form, placing my NT Login in the "SFTP Path" field!
       
Thanks in advance.
Reply all
Reply to author
Forward
0 new messages